Azure APIM operations not tracked in Terraform state after import

I’m importing APIs into Azure API Management (APIM) using Terraform, as shown below.

The issue:
While all the APIs and their operations defined in the OpenAPI (Swagger) specification are successfully created in APIM, only the APIs themselves are being tracked in the Terraform state file — the operations under these APIs are not managed in the state.

Is this the expected behaviour, or am I missing something?

Why this matters

I need to configure specific backends (either Logic App or Function App) for a few of these operations.

For Terraform to manage these, it needs to know about the API operations.

Here’s the relevant code snippet:

resource "azurerm_api_management_api" "api" {
  for_each = local.my_apis
  provider            = azurerm.hub
  name                = "${local.api_name}-${each.key}"
  resource_group_name = azurerm_api_management_product.abc.resource_group_name
  api_management_name = azurerm_api_management_product.abc.api_management_name
  revision            = "1"
  display_name        = "${each.value.display_name}"
  path                = "${each.value.gateway_path}"
  protocols           = ["https"]

  subscription_required = true 

  oauth2_authorization {
    authorization_server_name = local.abc_api_oauth2_provider_name
  }

  import {
    content_format = each.value.api_content_format
    content_value  = each.value.api_content_value <-- holds the swagger OpenAPI specification content.
  }
}

Any guidance or clarification would be greatly appreciated!

Found the solution.

You do not need a Terraform resource reference to the operation for you to create an operation policy and attach it. Instead, you can attach the policy directly using azurerm_api_management_api_operation_policy resource and referencing the Swagger operationId.

Example:

resource "azurerm_api_management_api_operation_policy" "my_op_policy" {
provider = azurerm.hub
 api_name = "<your api name>"
 api_management_name = data.azurerm_api_management.apim.name
 resource_group_name = data.azurerm_api_management.apim.resource_group_name
 operation_id = "<operationId from swagger>"
xml_content = templatefile("<policy path>", {
 backend_name = "<backend name>"
 method = "<operation method>"
 })
}

As long as the API exists in APIM and the operation exists and operation_id exactly matches the Swagger operationId — Terraform can apply and update the policy successfully. No explicit Terraform operation resource is required.