Skip to content

saif-api-service

This is a module for deploying an API to an App Service Plan and add that API to an API Management Service.

⚠️ Authentication Provider Changes

This module now supports dual authentication:

  • Corporate Tenant: Uses Entra ID (Microsoft) for internal/corporate authentication
  • External Tenant: Uses Okta for external user authentication

The API Management policies are configured to validate JWT tokens from both providers, allowing the API to serve both corporate and external users.

Feature flags

Optional capabilities such as Cosmos DB NoSQL, Blob Storage, and Service Bus queues are members of the single feature_flags object input, not top-level module arguments. In a Forge v3 project, the templates generate this module call as module "saif-appservices" in infra/api/app.generated.tf.

A module block accepts only one feature_flags argument, and Terraform rejects a second one as a duplicate. When you enable another feature and the module call already defines feature_flags (for example, a project scaffolded with database_type=cosmosdb already has the Cosmos DB members generated into it), add the new feature's members to that existing object instead of adding a new feature_flags = { ... } block:

module "saif-appservices" {
  # ... existing generated module arguments ...

  feature_flags = {
    # Existing members, e.g. from Cosmos DB
    cosmosdb_nosql_serverless = true

    # Members added for another feature, e.g. Blob Storage
    enable_blob_storage = true
    blob_storage_settings = {
      containers           = ["documents"]
      contributor_group_id = "12345678-1234-1234-1234-123456789abc"
    }
  }
}

The feature_flags row in the Inputs table below lists every member and its default. Each feature's development guide documents the members it needs.

Storage account key in Key Vault

Set feature_flags.storage_secret_keyvault_name to the name of an existing Key Vault in the shared services subscription to enable shared key access on the storage account and store its key1 as the secret <project_id>-storage-<environment_short_name>. It is valid only when enable_blob_storage, enable_storage_queue, or enable_storage_file is true. The vault must use Azure RBAC, and the principal running Terraform must already hold Key Vault Secrets Officer on it (granted in cloud-foundations; this module does not create the assignment). Clearing the setting removes the secret and disables shared key access again.

Providers

Name Version
azurerm.shared-services >= 4.46, < 5.0

Inputs

Name Description Type Default Required
allowed_tenants Tenants whose tokens the API accepts: 'corp' and/or 'ext'. Both (default) routes on the x-forward-tenant-origin header. Exactly one stamps x-forward-tenant-origin with that tenant and renders only its validation branch. Applies to api_policy_type = 'standard'. list(string)
[
"corp",
"ext"
]
no
api n/a
object({
name = string
type = string
open_api_file = string
})
n/a yes
api_policy_type APIM policy type. 'standard' uses Okta/Entra tenant-based routing. 'filevine' validates Filevine Identity Server JWTs for webhook endpoints. 'subscription_key' allows legacy apps to authenticate via APIM subscription keys (Experience APIs only). string "standard" no
application_secrets Secrets for your application from Azure Devops Library map(string) {} no
application_settings Settings for your application map(string) {} no
azure_logging_level The logging level for the Azure Infrastructure string "Error" no
create_staging_slot Whether to create a staging slot for the web app bool false no
deployed_by Deprecated. Per-run deploy identity is no longer written to tags because it changes on every run. Retained for backward compatibility with callers but ignored by this module. string "Terraform" no
enable_health_check Whether to enable the App Service health check. Defaults to true. Set to false to opt out. bool true no
environment The environment in which the resources are deployed string n/a yes
environment_short_name The short name of the environment string "" no
feature_flags Feature Flags for this module
object({
cosmosdb_nosql_serverless = optional(bool, false)
cosmosdb_nosql_serverless_settings = optional(object({
containers = map(object({
partition_key_path = string
ttl_in_days = optional(number) # TTL in days; null = TTL disabled, -1 = TTL enabled with no expiration, positive whole number = TTL in days
unique_keys = optional(list(list(string)), []) # each inner list = one unique key constraint (single-path or composite)
}))
}), {
containers = {}
})
cosmosdb_nosql_serverless_data_readers = optional(map(object({
object_id = optional(string)
group_name = optional(string)
})), {})
enable_blob_storage = optional(bool, false)
blob_storage_settings = optional(object({
containers = list(string)
contributor_group_id = string
}), {
containers = []
contributor_group_id = ""
})
enable_storage_queue = optional(bool, false)
storage_queue_settings = optional(object({
queues = list(string)
contributor_group_id = string
}), {
queues = []
contributor_group_id = ""
})
enable_storage_file = optional(bool, false)
storage_file_settings = optional(object({
file_shares = list(object({
name = string
quota_gb = optional(number, 100)
}))
contributor_group_id = string
}), {
file_shares = []
contributor_group_id = ""
})
# Name of an existing Key Vault in the shared services subscription (created in
# cloud-foundations) that receives the storage account key1 as a secret. Setting it
# also enables shared key access on the storage account. Empty = feature off.
storage_secret_keyvault_name = optional(string, "")
enable_document_intelligence = optional(bool, false)
enable_servicebus_queue = optional(bool, false)
# Keyed by a stable queue identity name (e.g. "intake", "retries") so an app can provision
# multiple, independent Service Bus queues. Defaults to a single "default" queue. Mirrors the
# full servicebus-queue module's per-queue settings so every module option is configurable here.
servicebus_queues = optional(map(object({
max_delivery_count = optional(number, 10)
lock_duration = optional(string, "PT30S")
default_message_ttl = optional(string, "P14D")
dead_lettering_on_message_expiration = optional(bool, true)
requires_duplicate_detection = optional(bool, false)
duplicate_detection_history_time_window = optional(string, "PT10M")
max_size_in_megabytes = optional(number, 1024)
dlq_reader_identities = optional(map(string), {})
dlq_manager_identities = optional(map(string), {})
})), {
default = {
max_delivery_count = 10
dead_lettering_on_message_expiration = true
requires_duplicate_detection = false
dlq_reader_identities = {}
dlq_manager_identities = {}
}
})
})
{
"blob_storage_settings": {
"containers": [],
"contributor_group_id": ""
},
"cosmosdb_nosql_serverless": false,
"cosmosdb_nosql_serverless_data_readers": {},
"cosmosdb_nosql_serverless_settings": {
"containers": {}
},
"enable_blob_storage": false,
"enable_document_intelligence": false,
"enable_servicebus_queue": false,
"enable_storage_file": false,
"enable_storage_queue": false,
"servicebus_queues": {
"default": {
"dead_lettering_on_message_expiration": true,
"dlq_manager_identities": {},
"dlq_reader_identities": {},
"max_delivery_count": 10,
"requires_duplicate_detection": false
}
},
"storage_file_settings": {
"contributor_group_id": "",
"file_shares": []
},
"storage_queue_settings": {
"contributor_group_id": "",
"queues": []
},
"storage_secret_keyvault_name": ""
}
no
is_experience_api Is this an Experience API bool false no
is_external_app Is this an external app bool false no
is_production Is this a production environment bool n/a yes
owner The name of the team that owns the resources string n/a yes
project_id The id of the project. This will be used to name the resources. string n/a yes
resource_location The location the resources will be deployed to. string "westus2" no
tags A map of tags to be applied to resources in the module map(string) n/a yes
tenant Deprecated — the Azure infra tenant is fixed to Corporate (see local.azure_tenant). Retained for backward compatibility with existing workspace variable sets (e.g. the Okta credentials variable set that injects tenant = "ext"), but no longer read by this module. string "Corporate" no

Outputs

Name Description
api_url Base URL of the API through Front Door (internal host, or external host when is_external_app is true).
application_client_id n/a
application_id n/a
application_object_id n/a
application_principal_client_id n/a
application_principal_id n/a
application_principal_object_id n/a
cosmosdb_account_endpoint n/a
cosmosdb_account_id n/a
cosmosdb_account_name n/a
organization_name n/a
resource_group_name n/a
storage_file_share_names Names of the file shares created from feature_flags.storage_file_settings.file_shares. Null when feature_flags.enable_storage_file is false.
storage_queue_names Names of the storage queues created from feature_flags.storage_queue_settings.queues. Null when feature_flags.enable_storage_queue is false.
subscription_primary_key Primary key of the APIM subscription scoped to this API. Only populated when api_policy_type = "subscription_key".
subscription_secondary_key Secondary key of the APIM subscription scoped to this API. Only populated when api_policy_type = "subscription_key".
user_assigned_identity_clientid n/a
user_assigned_identity_id n/a
user_assigned_identity_principalid n/a

Resources

  • resource.azurerm_app_configuration_key.application_secrets (/terraform-docs/main.tf#327)
  • resource.azurerm_app_configuration_key.application_settings (/terraform-docs/main.tf#315)
  • resource.azurerm_key_vault_secret.Application_Secrets (/terraform-docs/main.tf#219)
  • resource.azurerm_role_assignment.Application_Secret_Permissions (/terraform-docs/main.tf#300)

View source on GitHub