I want to get a list of Azure resources, example, we have the command Get-AzResourceGroup to get list of resources. Or Get-AzSqlServer -ResourceGroupName "ResourceGroup01" to list SQL Servers from a particular Resource Group. How can we do this in Terraform ?
0
votes
2 Answers
1
votes
Actually, you can use the data source:azurerm_resources to list the resources with the type in Azure as you want. But as I test, when I add the resource group, it only returns an empty list. I'm not sure if there is something wrong with my code. If it works as it shows, then it's the thing which you want and the example would like this:
data "azurerm_resources" "example" {
resource_group_name = "example-resources"
type = "Microsoft.Sql/servers"
}
0
votes
You could authenticate with Azure CLI with terraform and then use the CLI command to get the resources.
az resource list [--location]
[--name]
[--namespace]
[--resource-group]
[--resource-type]
[--subscription]
[--tag]