title | description | keywords | ms.topic | ms.date | ms.custom | adobe-target |
---|---|---|---|---|---|---|
Quickstart - Create an Azure resource group using Terraform |
Learn how to create an Azure resource group using Terraform |
azure devops terraform azure resource group |
quickstart |
04/24/2022 |
devx-track-terraform, mode-portal |
true |
Article tested with the following Terraform and Terraform provider versions:
[!INCLUDE Terraform abstract]
This article shows how to create an Azure resource group using Terraform.
In this article, you learn how to:
[!div class="checklist"]
- Create an Azure resource group to hold other Azure resources
- Verify (using Azure CLI and Azure PowerShell) the resource group was created
- Delete the resource group when finished using it
Note
The example code in this article is located in the Microsoft Terraform GitHub repo.
[!INCLUDE open-source-devops-prereqs-azure-subscription.md]
[!INCLUDE configure-terraform.md]
-
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-terraformmaster]
-
Create a file named
main.tf
and insert the following code:[!code-terraformmaster]
-
Create a file named
variables.tf
and insert the following code:[!code-terraformmaster]
-
Create a file named
outputs.tf
and insert the following code:[!code-terraformmaster]
[!INCLUDE terraform-init.md]
[!INCLUDE terraform-plan.md]
[!INCLUDE terraform-apply-plan.md]
To see the resource group name, run the following command:
echo "$(terraform output resource_group_name)"
Run az group show to display the resource group.
az group show --name <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