Azure API Management API Policy

This page shows how to write Terraform and Azure Resource Manager for API Management API Policy and write them securely.

azurerm_api_management_api_policy (Terraform)

The API Policy in API Management can be configured in Terraform with the resource name azurerm_api_management_api_policy. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L1
resource "azurerm_api_management_api_policy" "policy" {
  api_name            = var.name
  api_management_name = var.apim_name
  resource_group_name = var.rg_name

  xml_content = var.policy_xml
22-api-management-api-policy.tf#L1
resource "azurerm_api_management_api_policy" "hmi_apim_api_policy" {
  api_name            = azurerm_api_management_api.hmi_apim_api.name
  api_management_name = azurerm_api_management.hmi_apim.name
  resource_group_name = azurerm_resource_group.hmi_apim_rg.name

  xml_content = file("../template/api-policy.xml")
API.LogicAppHelper.tf#L23
resource "azurerm_api_management_api_policy" "utility_logicapps_helper" {
  resource_group_name = data.azurerm_api_management.eai_apim_instance.resource_group_name
  api_management_name = data.azurerm_api_management.eai_apim_instance.name

  api_name            = azurerm_api_management_api.utility_logicapps_helper.name

main.tf#L7
resource "azurerm_api_management_api_policy" "this" {
  api_management_name = var.api_management_name
  api_name            = var.api_name
  resource_group_name = var.resource_group_name
  xml_content         = var.xml_content
  xml_link            = var.xml_link
health_check.tf#L32
resource "azurerm_api_management_api_policy" "apim" {
  api_name            = azurerm_api_management_api.apim.name
  api_management_name = data.azurerm_api_management.apim.name
  resource_group_name = var.virtual_network_resource_group

  xml_content = <<XML
main.tf#L7
resource "azurerm_api_management_api_policy" "this" {
  api_management_name = var.api_management_name
  api_name            = var.api_name
  resource_group_name = var.resource_group_name
  xml_content         = var.xml_content
  xml_link            = var.xml_link
main.tf#L48
resource "azurerm_api_management_api_policy" "example" {
  api_name            = azurerm_api_management_api.SampleAPI.name
  api_management_name = azurerm_api_management_api.SampleAPI.api_management_name
  resource_group_name = azurerm_api_management_api.SampleAPI.resource_group_name

  xml_content = file("api_policy.xml")
main.tf#L37
resource "azurerm_api_management_api_policy" "api_management_api_policy" {
  api_name            = azurerm_api_management_api.api_management_api.name
  api_management_name = var.api_management_name
  resource_group_name = var.resource_group_name

  xml_content = var.policy_xml
main.tf#L38
resource "azurerm_api_management_api_policy" "api_policy" {
    for_each = { for api-policy in var.api-policy : api-policy.api_name => api-policy }

  api_name            = azurerm_api_management_api.api[each.value.api_name].name
  api_management_name = azurerm_api_management_api.api[each.value.api_name].api_management_name
  resource_group_name = azurerm_api_management_api.api[each.value.api_name].resource_group_name
apis.tf#L18
resource "azurerm_api_management_api_policy" "example" {
  api_name            = azurerm_api_management_api.example.name
  api_management_name = azurerm_api_management.apim.name
  resource_group_name = azurerm_resource_group.rg.name

  xml_content = <<XML

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages an API Management API Policy

Microsoft.ApiManagement/service/apis/policies (Azure Resource Manager)

The service/apis/policies in Microsoft.ApiManagement can be configured in Azure Resource Manager with the resource name Microsoft.ApiManagement/service/apis/policies. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Parameters

  • apiVersion required - string
  • name required - string

    The identifier of the Policy.

  • properties required
      • format optional - string

        Format of the policyContent.

      • value required - string

        Contents of the Policy as defined by the format.

  • type required - string

Frequently asked questions

What is Azure API Management API Policy?

Azure API Management API Policy is a resource for API Management of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure API Management API Policy?

For Terraform, the julianpiornoglobant/CoE-API, hmcts/fh-hmi-api-gateway and michaelstephensonuk/IntegrationPlaybook-Samples-AzureAPIM source code examples are useful. See the Terraform Example section for further details.