title | description | ms.topic | service | ms.service | ms.date | ms.custom | adobe-target | content_well_notification | ai-usage | |
---|---|---|---|---|---|---|---|---|---|---|
Quickstart: Create an Azure resource group using Terraform |
In this article, you learn how to create an Azure resource group using Terraform |
quickstart |
azure |
azure |
10/26/2023 |
devx-track-terraform |
true |
|
ai-assisted |
This article shows how to create an Azure resource group using Terraform.
[!INCLUDE Terraform abstract]
In this article, you learn how to:
[!div class="checklist"]
- Create a random value for the Azure resource group name using random_pet.
- Create an Azure resource group using azurerm_resource_group.
Note
The sample code for this article is located in the Azure Terraform GitHub repo. You can view the log file containing the test results from current and previous versions of Terraform.
See more articles and sample code showing how to use Terraform to manage Azure resources
-
Create a directory in which to test the sample Terraform code and make it the current directory.
-
Create a file named
providers.tf
and insert the following code::::code language="Terraform" source="~/../terraform_samples/quickstart/101-resource-group/providers.tf":::
-
Create a file named
main.tf
and insert the following code::::code language="Terraform" source="~/../terraform_samples/quickstart/101-resource-group/main.tf":::
-
Create a file named
variables.tf
and insert the following code::::code language="Terraform" source="~/../terraform_samples/quickstart/101-resource-group/variables.tf":::
-
Create a file named
outputs.tf
and insert the following code::::code language="Terraform" source="~/../terraform_samples/quickstart/101-resource-group/outputs.tf":::
[!INCLUDE terraform-init.md]
[!INCLUDE terraform-plan.md]
[!INCLUDE terraform-apply-plan.md]
-
Get the Azure resource group name.
resource_group_name=$(terraform output -raw resource_group_name)
-
Run az group show to display the resource group.
az group show --name $resource_group_name
-
Get the Azure resource group name.
$resource_group_name=$(terraform output -raw resource_group_name)
-
Run Get-AzResourceGroup to display the resource group.
Get-AzResourceGroup -Name $resource_group_name
[!INCLUDE terraform-plan-destroy.md]
Troubleshoot common problems when using Terraform on Azure
[!div class="nextstepaction"] Learn more about using Terraform in Azure