How to Use The Terraform Azure AzAPI Provider

The AzAPI Terraform provider is a plugin for Terraform that allows you to deploy Azure resources that are not yet available with the AzureRM provider.

Every Azure Terraform developer knows that the biggest challenge of Terraform when it comes to Azure is the lack of support for resources in private or public previews.

Because of the above reason, Terraform and Microsoft made the AzAPI provider available. The provider talks directly to the Azure API and uses JSON code to configure resources.

How to use the AzAPI Provider

To use the provider, we first need to add it on top of our Azure provider, as shown below. I am using the AzureRM provider and also the AzAPI.

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

    azapi = {
      source = "Azure/azapi"
    }
  }

provider "azapi" {
}

I have to say that using the AzAPI provider can be challenging because of the complexity of the provider and the fact that we use Azure ARM and Terraform together to get the configuration to work.

The code in the example below shows how to create an Azure DNS resolver. Notice in the example the API version (type) and the JSON code where we specify the values from the API.

resource "azapi_resource" "dnsresolver" {
  type      = "Microsoft.Network/dnsResolvers@2022-07-01"
  name      = "dnsresolver"
  parent_id = azurerm_resource_group.test.id
  location  = azurerm_resource_group.test.location

  body = jsonencode({
    properties = {
      virtualNetwork = {
        id = azurerm_virtual_network.vnet.id
      }
    }
  })
}

For more examples, please check the AzAPI GitHub repo and the Microsoft Learn documentation for AzAPI.

Processing…
Success! You're on the list.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.