Azure API Management Subscription

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

azurerm_api_management_subscription (Terraform)

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

Example Usage from GitHub

main.tf#L2
resource "azurerm_api_management_subscription" "subscription" {

  api_management_name   = var.apim_name
  resource_group_name   = var.resource_group_name
  user_id               = var.user_id
  product_id            = var.product_id
main.tf#L2
resource "azurerm_api_management_subscription" "subscription" {

  api_management_name   = var.apim_name
  resource_group_name   = var.resource_group_name
  user_id               = var.user_id
  product_id            = var.product_id
main.tf#L1
resource "azurerm_api_management_subscription" "module" {
  api_management_name = var.apim_name
  resource_group_name = var.rg_name

  user_id      = var.apim_user_id
  product_id   = var.apim_product_id
main.tf#L2
resource "azurerm_api_management_subscription" "subscription" {

  api_management_name   = var.service_settings.api_management_name
  resource_group_name   = var.context.resource_group_name
  user_id               = var.service_settings.user_id
  product_id            = var.service_settings.product_id
main.tf#L1
resource "azurerm_api_management_subscription" "subscription" {
  count               = length(var.subscription)
  api_management_name = element(var.api_management_name, lookup(var.subscription[count.index], "api_management_id"))
  display_name        = lookup(var.subscription[count.index], "display_name")
  product_id          = element(var.product_id, lookup(var.subscription[count.index], "product_id"))
  resource_group_name = var.resource_group_name
main.tf#L7
resource "azurerm_api_management_subscription" "this" {
  api_management_name = var.api_management_name
  display_name        = var.display_name
  primary_key         = var.primary_key
  product_id          = var.product_id
  resource_group_name = var.resource_group_name
main.tf#L7
resource "azurerm_api_management_subscription" "this" {
  api_management_name = var.api_management_name
  display_name        = var.display_name
  primary_key         = var.primary_key
  product_id          = var.product_id
  resource_group_name = var.resource_group_name

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 a Subscription within a API Management Service.

Microsoft.ApiManagement/service/subscriptions (Azure Resource Manager)

The service/subscriptions in Microsoft.ApiManagement can be configured in Azure Resource Manager with the resource name Microsoft.ApiManagement/service/subscriptions. 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

    Subscription entity Identifier. The entity represents the association between a user and a product in API Management.

  • properties required
      • allowTracing optional - boolean

        Determines whether tracing can be enabled

      • displayName required - string

        Subscription name.

      • ownerId optional - string

        User (user id path) for whom subscription is being created in form /users/{userId}

      • primaryKey optional - string

        Primary subscription key. If not specified during request key will be generated automatically.

      • scope required - string

        Scope like /products/{productId} or /apis or /apis/{apiId}.

      • secondaryKey optional - string

        Secondary subscription key. If not specified during request key will be generated automatically.

      • state optional - string

        Initial subscription state. If no value is specified, subscription is created with Submitted state. Possible states are active – the subscription is active, suspended – the subscription is blocked, and the subscriber cannot call any APIs of the product, submitted – the subscription request has been made by the developer, but has not yet been approved or rejected, rejected – the subscription request has been denied by an administrator, cancelled – the subscription has been cancelled by the developer or administrator, expired – the subscription reached its expiration date and was deactivated.

  • type required - string

Frequently asked questions

What is Azure API Management Subscription?

Azure API Management Subscription 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 Subscription?

For Terraform, the markti/terraform-azure, aadi555/azurerm and jessewilk/terraform source code examples are useful. See the Terraform Example section for further details.