Skip to content

Latest commit

 

History

History
108 lines (65 loc) · 3.42 KB

create-resource-group.md

File metadata and controls

108 lines (65 loc) · 3.42 KB
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

Quickstart: Create an Azure resource group using Terraform

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.

Prerequisites

[!INCLUDE open-source-devops-prereqs-azure-subscription.md]

[!INCLUDE configure-terraform.md]

Implement the Terraform code

  1. Create a directory in which to test the sample Terraform code and make it the current directory.

  2. Create a file named providers.tf and insert the following code:

    [!code-terraformmaster]

  3. Create a file named main.tf and insert the following code:

    [!code-terraformmaster]

  4. Create a file named variables.tf and insert the following code:

    [!code-terraformmaster]

  5. Create a file named outputs.tf and insert the following code:

    [!code-terraformmaster]

Initialize Terraform

[!INCLUDE terraform-init.md]

Create a Terraform execution plan

[!INCLUDE terraform-plan.md]

Apply a Terraform execution plan

[!INCLUDE terraform-apply-plan.md]

Verify the results

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>

Clean up resources

[!INCLUDE terraform-plan-destroy.md]

Troubleshoot Terraform on Azure

Troubleshoot common problems when using Terraform on Azure

Next steps

[!div class="nextstepaction"] Learn more about using Terraform in Azure