Create Azure Resource Group using Terraform

Terraform can be used to create multiple resource groups in Azure and the simplest among them is creating a resource group, the below code can be used to create a resource group in Azure. For creating a resource group, name and location of the resource group is mandatory and the provider is “azurerm_resource_group”

resource "azurerm_resource_group" "TerraformGroup" {
  name = "TerraformTest1"
  location = "South Central US"  
}

The same code can be also used with additional arguments like Tags and they are completely optional.And if you need you can also use Timeouts to create a resource group which would generally not needed

resource "azurerm_resource_group" "TerraformGroup" {
  name = "TerraformTest1"
  location = "South Central US"  
  tags = {
    foo = "bar"
  }
}


The full code just to create Resource group would look like this

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.0.0"
    }
  }
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
  features {}
}


resource "azurerm_resource_group" "TerraformGroup" {
  name = "TerraformTest1"
  location = "South Central US"  
}

You may also like...