API Management

Farmer provides builders for an Azure API Management service and its supported child resources. Each builder emits the correct ARM resource type, parent-qualified name, and parent dependency.

API Management service

The service builder is apiManagementService.

KeywordDescription
nameSets the API Management service name.
locationSets the Azure region.
publisher_nameSets the publisher name shown by the service.
publisher_emailSets the publisher email address.
skuSets the service tier: Consumption, Developer, Basic, Standard, or Premium.
capacitySets the number of units for the selected SKU.
public_network_accessSets public network access, normally Enabled or Disabled.
virtual_network_typeSets the virtual network mode: None, External, or Internal.
disable_gatewayDisables the managed gateway.
custom_propertyAdds a gateway custom property by key and value.
add_tag / add_tagsAdds one or more resource tags.
open Farmer
open Farmer.Builders.ApiManagement

let apim = apiManagementService {
    name "my-api-management"
    location Location.WestEurope
    publisher_name "Contoso"
    publisher_email "api-admin@contoso.com"
    sku ApiManagementSku.Developer
    capacity 1
    public_network_access "Enabled"
    virtual_network_type "None"
    custom_property "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10" "false"
    add_tag "environment" "production"
}

API

The API builder is apiManagementApi. It creates Microsoft.ApiManagement/service/apis and automatically appends the revision to the ARM name (name;rev=<revision>).

KeywordDescription
serviceSets the parent API Management service name.
nameSets the logical API name.
display_nameSets the API display name.
pathSets the gateway URL path for the API.
protocolsSets the supported protocol list, for example [ "https" ].
service_urlSets the backend service URL.
descriptionSets the API description.
api_versionSets the API version label.
revisionSets the API revision, defaulting to "1".
subscription_requiredControls whether callers need a subscription key.
let catalogApi = apiManagementApi {
    service "my-api-management"
    name "catalog"
    display_name "Catalog API"
    path "catalog"
    protocols [ "https" ]
    service_url "https://catalog.contoso.com"
    description "The catalog API"
    revision "1"
    subscription_required true
}

API operation

The operation builder is apiManagementOperation. It creates Microsoft.ApiManagement/service/apis/operations.

KeywordDescription
serviceSets the parent API Management service name.
apiSets the revision-qualified API name, for example ResourceName "catalog;rev=1".
nameSets the operation name.
display_nameSets the operation display name.
methodSets the HTTP method.
url_templateSets the operation URL template.
descriptionSets the operation description.
let listCatalog = apiManagementOperation {
    service "my-api-management"
    api "catalog;rev=1"
    name "list"
    display_name "List catalog items"
    method "GET"
    url_template "/items"
    description "Lists catalog items"
}

Product

The product builder is apiManagementProduct. It creates Microsoft.ApiManagement/service/products.

KeywordDescription
serviceSets the parent API Management service name.
nameSets the product name.
display_nameSets the product display name.
descriptionSets the product description.
termsSets the terms shown to subscribers.
subscription_requiredControls whether subscriptions are required.
approval_requiredControls whether subscriptions require approval.
subscriptions_limitSets the maximum number of subscriptions.
stateSets the product state, such as published or notPublished.
let publicProduct = apiManagementProduct {
    service "my-api-management"
    name "public"
    display_name "Public APIs"
    description "APIs available to external consumers"
    subscription_required false
    approval_required false
    state "published"
}

Backend

The backend builder is apiManagementBackend. It creates Microsoft.ApiManagement/service/backends.

KeywordDescription
serviceSets the parent API Management service name.
nameSets the backend name.
urlSets the backend endpoint URL.
protocolSets the backend protocol, normally http or https.
titleSets a display title.
descriptionSets the backend description.
resource_idAssociates the backend with an Azure resource ID.
let catalogBackend = apiManagementBackend {
    service "my-api-management"
    name "catalog-backend"
    url "https://catalog.contoso.com"
    protocol "https"
    title "Catalog backend"
}

Named value

The named-value builder is apiManagementNamedValue. It creates Microsoft.ApiManagement/service/namedValues.

KeywordDescription
serviceSets the parent API Management service name.
nameSets the named-value name.
display_nameSets the display name.
valueSets the value available to policies.
secretMarks the value as secret.
tagsSets the named-value tag list.
let catalogKey = apiManagementNamedValue {
    service "my-api-management"
    name "catalog-key"
    display_name "Catalog API key"
    value "secret-value"
    secret
    tags [ "catalog"; "external" ]
}

Policy

The policy builder is apiManagementPolicy. It creates a policy resource below the selected scope.

KeywordDescription
serviceSets the parent API Management service name.
scopeSets the policy scope, such as service or apis.
apiSets the parent revision-qualified API name when scope is apis.
nameSets the policy resource name.
formatSets the policy format, normally rawxml.
xmlSets the policy XML document.
let catalogPolicy = apiManagementPolicy {
    service "my-api-management"
    scope "apis"
    api "catalog;rev=1"
    name "policy"
    format "rawxml"
    xml "<policies><inbound><base /></inbound><outbound><base /></outbound></policies>"
}

Deploying the resources

All builders implement Farmer’s normal builder interface and can be composed in one template:

let template =
    arm {
        add_resources [
            apim
            catalogApi
            listCatalog
            publicProduct
            catalogBackend
            catalogKey
            catalogPolicy
        ]
    }

apiManagementChild is retained as an escape hatch for an Azure child resource that does not yet have a typed Farmer builder. It is not required for the supported builders above and is not the preferred API for them.