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​
| Action | Runs |
|---|---|
plan | Nothing. Azure deployment stacks have no what-if, so the step logs that it skips the plan. |
provision | Checkov, creates the resource group (scope group), az stack <scope> create, then publishes resources |
decommission | az 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.bicepfor policy and compliance violations onprovision.
Configuration​
| Configuration Option | Type | Default | Description |
|---|---|---|---|
azure_authentication | object | Overrides the credentials read from the azure_authentication dependency, field by field. See Authentication. | |
azure_authentication.client_id | string | Azure client (application) ID. | |
azure_authentication.client_secret | string | Azure client secret. Setting this selects service principal (secret) authentication. | |
azure_authentication.tenant_id | string | Azure tenant ID. | |
azure_authentication.subscription_id | string | (identity default) | Subscription to deploy into. If unset, the authenticated identity's default subscription is used. |
location | string | eastus | Azure region for the resource group (scope group) or the stack (scope sub). region is read when location is not set. |
scope | string | group | Deployment scope: group or sub. |
show_output | boolean | false | Prints the stack output on success and failure. The output can contain secrets. |
action_on_unmanage | string | deleteAll | Fate of managed resources when removed from the template or on decommission. See Deployment Stacks. |
deny_settings_mode | string | none | Protection against changes to managed resources made outside the stack. See Deployment Stacks. |
resource_group | string | md_metadata.name_prefix | Resource group name. Scope group only. |
create_resource_group | boolean | true | Creates the resource group on provision. When false, the resource group must already exist. Scope group only. |
delete_resource_group | boolean | true | Deletes the resource group on decommission. Scope group only. |
checkov.enable | boolean | true | Runs Checkov. |
checkov.quiet | boolean | true | Shows only failed checks (--quiet). |
checkov.halt_on_failure | boolean | false | Fails the deployment on a failed check (drops --soft-fail). |
Authentication​
The provisioner reads the credentials from a dependency named azure_authentication, with this shape:
{
"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.
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.
| Method | Selected when | Required fields |
|---|---|---|
| Service principal (secret) | client_secret is set | client_id, client_secret, tenant_id |
| Workload identity | the 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 set | client_id |
| Managed identity (system-assigned) | none of the above match | none |
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, anddelete_resource_groupapply.sub: a subscription. The stack is created inlocation.
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:
{
"foo": "bar",
"baz": {
"nested": "field"
}
}
becomes:
{
"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:
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:
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:
{
"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:
{
"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.