Skip to main content

Bicep Provisioner

Runs a step with Bicep and Azure deployment stacks. Source: provisioner-bicep.

Structure​

The step's path holds template.bicep. Other files in the directory are not deployed.

Actions​

ActionRuns
planNothing. Azure deployment stacks have no what-if, so the step logs that it skips the plan.
provisionCheckov, creates the resource group (scope group), az stack <scope> create, then publishes resources
decommissionaz stack <scope> delete, deletes the resource group (scope group), then deletes the step's resources

The stack is named <md_metadata.name_prefix>-<path>.

Tooling​

  • Checkov scans template.bicep for policy and compliance violations on provision.

Configuration​

Configuration OptionTypeDefaultDescription
azure_authenticationobjectOverrides the credentials read from the azure_authentication dependency, field by field. See Authentication.
azure_authentication.client_idstringAzure client (application) ID.
azure_authentication.client_secretstringAzure client secret. Setting this selects service principal (secret) authentication.
azure_authentication.tenant_idstringAzure tenant ID.
azure_authentication.subscription_idstring(identity default)Subscription to deploy into. If unset, the authenticated identity's default subscription is used.
locationstringeastusAzure region for the resource group (scope group) or the stack (scope sub). region is read when location is not set.
scopestringgroupDeployment scope: group or sub.
show_outputbooleanfalsePrints the stack output on success and failure. The output can contain secrets.
action_on_unmanagestringdeleteAllFate of managed resources when removed from the template or on decommission. See Deployment Stacks.
deny_settings_modestringnoneProtection against changes to managed resources made outside the stack. See Deployment Stacks.
resource_groupstringmd_metadata.name_prefixResource group name. Scope group only.
create_resource_groupbooleantrueCreates the resource group on provision. When false, the resource group must already exist. Scope group only.
delete_resource_groupbooleantrueDeletes the resource group on decommission. Scope group only.
checkov.enablebooleantrueRuns Checkov.
checkov.quietbooleantrueShows only failed checks (--quiet).
checkov.halt_on_failurebooleanfalseFails the deployment on a failed check (drops --soft-fail).

Authentication​

The provisioner reads the credentials from a dependency named azure_authentication, with this shape:

json
{
"client_id": "00000000-0000-0000-0000-000000000000",
"client_secret": "<client secret>",
"tenant_id": "00000000-0000-0000-0000-000000000000",
"subscription_id": "00000000-0000-0000-0000-000000000000"
}

config.azure_authentication is merged over the dependency field by field. Use it to supply the whole credential when your resource type has another shape, or to override one field, such as subscription_id.

note

When there is no azure_authentication dependency, the provisioner reads the data block of an azure_service_principal dependency. This is deprecated. Rename the dependency to azure_authentication.

The provisioner then uses the first method in this table whose condition matches. For example, when both client_secret and a workload identity token are present, it uses the service principal.

MethodSelected whenRequired fields
Service principal (secret)client_secret is setclient_id, client_secret, tenant_id
Workload identitythe AZURE_FEDERATED_TOKEN_FILE environment variable is present (injected by the AKS workload identity webhook)client_id, tenant_id, from config, the dependency, or the env vars the webhook injects
Managed identity (user-assigned)only client_id is setclient_id
Managed identity (system-assigned)none of the above matchnone

subscription_id is independent of the method. When it is set, it selects the subscription. Otherwise the identity's default subscription is used.

Deployment Scope​

The provisioner supports two of the Azure Resource Manager deployment scopes:

  • group (default): a resource group. resource_group, create_resource_group, and delete_resource_group apply.
  • sub: a subscription. The stack is created in location.

Management group and tenant scopes are not supported.

Deployment Stacks​

The provisioner deploys template.bicep as an Azure deployment stack, which manages its resources as one unit. Two settings control the stack.

action_on_unmanage​

What happens to a managed resource when it is removed from the template or the stack is deleted: deleteAll (default), deleteResources, or detachAll. See Control detachment and deletion.

Decommission deletes the stack with action_on_unmanage applied, so detachAll leaves the Azure resources in place. Keep deleteAll to remove them.

deny_settings_mode​

Blocks changes to managed resources made outside the stack: none (default), denyDelete, or denyWriteAndDelete. See Protect managed resources.

Inputs​

Bicep reads parameters from JSON, with each value nested under a value key. The provisioner rewrites params.json and connections.json this way. For example:

json
{
"foo": "bar",
"baz": {
"nested": "field"
}
}

becomes:

json
{
"foo": {
"value": "bar"
},
"baz": {
"value": {
"nested": "field"
}
}
}

Each param and each dependency is a Bicep parameter of the same name. mass bundle build appends a typed param declaration to template.bicep for each one it does not already declare. To reshape a value, use Bicep variables.

Resources​

After the stack deploys, the provisioner renders a jq template for each resource. The template is steps[].resources.<name>.template in massdriver.yaml, or a resource_<name>.jq file in path. See Provisioners: Resources.

The template reads params, connections, envs, secrets, and outputs. outputs holds the stack's Bicep outputs, unwrapped from their value keys.

Take a storage account bundle with one param, one dependency, and one resource:

massdriver.yamlyaml
steps:
- path: src
provisioner: bicep

params:
required:
- region
properties:
region:
type: string

dependencies:
azure_authentication:
resource_type: azure-service-principal@~1
required: true

resources:
storage_account:
resource_type: azure-storage-account-blob@~1
required: true

Output the values the resource needs:

bicep
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = {
...
}

output storageAccountId string = storageAccount.id
output storageAccountEndpoint string = storageAccount.properties.primaryEndpoints.blob

The template's input is:

json
{
"params": {
"region": "eastus"
},
"connections": {
"azure_authentication": {
"client_id": "00000000-1111-2222-3333-444444444444",
"client_secret": "s0mes3cr3tv@lue",
"subscription_id": "00000000-1111-2222-3333-444444444444",
"tenant_id": "00000000-1111-2222-3333-444444444444"
}
},
"envs": {},
"secrets": {},
"outputs": {
"storageAccountEndpoint": "https://storageaccountname.blob.core.windows.net/",
"storageAccountId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/resource-group-name/providers/Microsoft.Storage/storageAccounts/storageaccountname"
}
}

Build the resource in src/resource_storage_account.jq:

src/resource_storage_account.jqjq
{
"infrastructure": {
"ari": .outputs.storageAccountId,
"endpoint": .outputs.storageAccountEndpoint
},
"specs": {
"azure": {
"region": .params.region
}
}
}

To build the whole payload in Bicep instead, output it as an object, such as output storage_account object = {...}, and return .outputs.storage_account from the template.