terraforming with azure azapi - solving the issue for you when you have to make a manual REST API call to azure

 AzApi helps solving the issue for you when you have to make a manual REST API call to azure. It is better than null script apprach whereby your:-

  • State fully managed
  • No external script dependency or PowerShell requirement
  • Handles the API version explicitly
  • Native depends_on support
  • Idempotent by design
  • Besides it is often recommended to use "azapi provider" > ARM template deployment > null resource"

    This is an actual scenario when configuring Azure Foundry capability host - we have to initiate REST API call as there's no other sdk available. 

    To be able to do that we will use azapi providers and the sample code are shown here:-


    terraform {
      required_providers {
        azapi = {
          source  = "azure/azapi"
          version = "~> 2.0"
        }
        azurerm = {
          source  = "hashicorp/azurerm"
          version = "~> 3.0"
        }
      }
    }

    # ── Account-level capability host ──────────────────────────────────────────
    resource "azapi_resource" "account_capability_host" {
      type      = "Microsoft.CognitiveServices/accounts/capabilityHosts@2025-06-01"
      name      = "agents-capability-host"
      parent_id = azurerm_cognitive_account.foundry.id

      body = {
        properties = {
          capabilityHostKind = "Agents"
        }
      }
    }

    # ── Project-level capability host ──────────────────────────────────────────
    resource "azapi_resource" "project_capability_host" {
      type      = "Microsoft.CognitiveServices/accounts/projects/capabilityHosts@2025-06-01"
      name      = "agents-capability-host"
      parent_id = azapi_resource.foundry_project.id

      body = {
        properties = {
          capabilityHostKind      = "Agents"
          threadStorageConnections = [var.cosmosdb_connection_name]
          vectorStoreConnections   = [var.ai_search_connection_name]
          storageConnections       = [var.storage_connection_name]
        }
      }

      depends_on = [azapi_resource.account_capability_host]
    }

    Comments

    Popular posts from this blog

    mongosh install properly

    gemini cli getting file not defined error

    vllm : Failed to infer device type