Deploy Azure ARM Template with Terraform

In this blog post, I will show you how to deploy Azure ARM templates with Terraform in case the Terraform provider is missing the feature.

ARM

In some cases, you might come to situations where the Azure Terraform provider is missing a service or feature in Azure that is available in ARM. Similar to running Azure CLI commands with Terraform we can also use ARM.

ARM Template file

In my case and for this configuration example, I have an Azure ARM template (shown below) that deploys an Azure storage account.

To deploy the template with Terraform, I names it azuredeploy.jason and saved in the same folder as my Terraform configuration.

{
   "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   "resources": [
     {
       "type": "Microsoft.Storage/storageAccounts",
       "apiVersion": "2019-04-01",
       "name": "ntweeklycomst01",
       "location": "west us",
       "sku": {
         "name": "Standard_LRS"
       },
       "kind": "StorageV2",
       "properties": {
         "supportsHttpsTrafficOnly": true
       }
     }
   ]
 }

I am referencing the ARM template file and creating an Azure resource group in the following Terraform configuration.

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

provider "azurerm" {
  features {  }
}

resource "azurerm_resource_group" "rg" {
  name     = "TFRDemo"
  location = "australiasoutheast"
}
resource "azurerm_template_deployment" "arm" {
  name                = "arm"
  resource_group_name = azurerm_resource_group.rg.name
  template_body       = file("azuredeploy.jason")


  deployment_mode = "Incremental"
}

Posted

in

,

by