azapi_resource

This resource can access any existing Azure resource manager resource.

Example Usage

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

provider "azapi" {
  enable_hcl_output_for_data_source = true
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-rg"
  location = "west europe"
}

resource "azurerm_container_registry" "example" {
  name                = "example"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku                 = "Premium"
  admin_enabled       = false
}

data "azapi_resource" "example" {
  name      = "example"
  parent_id = azurerm_resource_group.example.id
  type      = "Microsoft.ContainerRegistry/registries@2020-11-01-preview"

  response_export_values = ["properties.loginServer", "properties.policies.quarantinePolicy.status"]
}

// it will output "registry1.azurecr.io"
output "login_server" {
  value = data.azapi_resource.example.output.properties.loginServer
}

// it will output "disabled"
output "quarantine_policy" {
  value = data.azapi_resource.example.output.properties.policies.quarantinePolicy.status
}

Arguments Reference

The following arguments are supported:

For child level resources, the parent_id should be the ID of its parent resource, for example, subnet resource's parent_id is the ID of the vnet.

For type Microsoft.Resources/resourceGroups, the parent_id could be omitted, it defaults to subscription ID specified in provider or the default subscription(You could check the default subscription by azure cli command: az account show).


{
  properties = {
    loginServer = "registry1.azurecr.io"
    policies = {
      quarantinePolicy = {
        status = "disabled"
      }
    }
  }
}

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

// it will output "registry1.azurecr.io"
output "login_server" {
  value = data.azapi_resource.example.output.properties.loginServer
}

// it will output "disabled"
output "quarantine_policy" {
  value = data.azapi_resource.example.output.properties.policies.quarantinePolicy.status
}

A identity block exports the following:

Timeouts

The timeouts block allows you to specify timeouts for certain actions: