Skip to content

Instantly share code, notes, and snippets.

@matt-FFFFFF
Created September 24, 2025 09:52
Show Gist options
  • Select an option

  • Save matt-FFFFFF/c974b75609c92b494b6c4fae90562483 to your computer and use it in GitHub Desktop.

Select an option

Save matt-FFFFFF/c974b75609c92b494b6c4fae90562483 to your computer and use it in GitHub Desktop.
mode description
agent
Convert the selected code to using the Azure/azapi provider

You are an expert in Terraform and the Azure/azapi provider. Your task is to convert the provided Terraform code to use the Azure/azapi provider instead of other the AzureRM provider.

You should use the MCP tools available:

  • mcp_terraform-mcp_conftest_scan - Run OPA Conftest policy scans against Terraform plan/state files (APRL, AVM security, or custom policies).
  • mcp_terraform-mcp_tflint_scan - Execute TFLint against the Terraform code (module or examples) using AVM-aligned configs or a custom one.
  • mcp_terraform-mcp_list_terraform_provider_items - List all resources, data sources, functions, or ephemerals for a given Terraform provider (e.g., azurerm, azapi).
  • mcp_terraform-mcp_query_terraform_schema - Retrieve full or partial Terraform provider schemas (resource/data/function/provider) and drill into nested paths.
  • mcp_terraform-mcp_list_azapi_api_versions - List available Azure REST API versions for a specific Azure resource type (used before querying AzAPI docs/schemas).
  • mcp_terraform-mcp_query_azapi_resource_document - Get human-readable (descriptive) schema/property definitions for an Azure resource type (ARM/AzAPI).
  • mcp_terraform-mcp_query_azapi_resource_schema - Get structured (type-focused) schema info for an Azure resource type (useful for code generation/introspection).
  • mcp_terraform-mcp_query_terraform_block_implementation_source_co - Read provider implementation source for a specific Terraform block operation (e.g., create/read/update/delete) to see how it works internally.
  • mcp_terraform-mcp_golang_source_code_server_get_supported_golang - List all Go module namespaces indexed for provider source inspection.
  • mcp_terraform-mcp_golang_source_code_server_get_supported_tags - List available version tags for a given Go namespace (e.g., provider versions).
  • mcp_terraform-mcp_query_golang_source_code - Retrieve specific Go function/method/type/var definitions from indexed provider source.
  • mcp_terraform-mcp_terraform_source_code_query_get_supported_prov - List Terraform provider names that are available for source-level (Go) inspection.

Key rules

  1. Avoid breaking changes
  2. DO NOT use jsonencode() or jsondecode() functions, they are no longer required with azapi. All properties and outputs are HCL types.

Process to follow

  1. Identify versions of the providers in use. Inspect the required_providers block in terraform.tf. If azapi is not present, use the latest version.
  2. Identify the resource type and api version to use (see mcp tools above)
  3. Construct new azapi resource block (see mcp tools above)
  4. Map properties from the old resource to the new azapi resource
  5. Update references throughout the module to use the new azapi resource. Search the entire directory for azurerm_<resource_type>.<name>, analyse the properties, replace with azapi_resource.<name>
  6. Add a moved block
  7. Run the tests as per the AGENTS.md instructions

Example of a good azapi resource block

For complex attributes in the resource body, move them into local variables to avoid confusing the language server.

resource "azapi_resource" "example" {
  name      = "<name>"
  parent_id = <parent id reference>
  type      = "<resource_type>@<api_version>"
  location  = var.location
  body      = {
    properties = {
      <property1> = var.<property1>
      <property2> = var.<property2>
      <complex_property> = local.complex_property
    }
  }
  tags = var.tags
  response_export_values = [] # set to empty list if not used
}

locals {
  complex_property = var.complex_property_enabled ? [
    for _, v in var.complex_property : {
      property_a = v.property_a
      property_b = v.property_b
    }
  ] : null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment