Skill 48 · Azure Developer CLI
Subchapter 48.1
references/iac-and-environments.mdMarkdown7 KBView on GitHub
Use Bicep when:
Bicep is AZD’s default IaC provider.
Use Terraform when:
Current Microsoft documentation marks AZD Terraform support as beta. Surface this constraint and do not migrate a project to Terraform merely for familiarity.
Keep main.bicep as an orchestration layer:
infra/
|-- main.bicep
|-- main.parameters.json
|-- modules/
| |-- core/
| |-- data/
| |-- identity/
| |-- observability/
| |-- services/targetScope intentionally.uniqueString with stable scope inputs where global uniqueness is required.Use main.parameters.json to map AZD environment values into Bicep:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environmentName": {
"value": "${AZURE_ENV_NAME}"
},
"location": {
"value": "${AZURE_LOCATION}"
}
}
}Match those values in the entry point:
@description('Stable name of the AZD deployment environment.')
@minLength(1)
param environmentName string
@description('Primary Azure region for this deployment.')
param location stringUse outputs as the contract between provisioning and later AZD phases:
output SERVICE_API_ENDPOINT_URL string = api.outputs.endpointChoose stable output names because services, hooks, and pipelines may consume them as environment variables.
When using AZD environment secrets with Bicep:
@secure().main.parameters.json..bicepparam files.infra.provider: terraform explicitly in azure.yaml..tf files under the configured infrastructure path.sensitive, but remember that sensitive values can still exist in state..tfstate, plan files, crash logs, or provider credentials.Terraform’s Azure provider uses Azure CLI authentication by default and does not use the AZD credential cache. Prefer the documented single-sign-in configuration:
azd config set auth.useAzCliAuth true
az loginOtherwise, both azd auth login and az login are required.
Configure a protected remote backend before azd pipeline config or collaborative deployments:
AZD reads Terraform backend settings from infra/provider.conf.json when configured according to the official Terraform integration.
AZD stores local environment state under:
.azure/
|-- config.json
|-- <environment-name>/
|-- .env
|-- config.jsonThe entire .azure directory should remain out of source control.
Use names that make ownership and lifecycle clear:
<project>-dev, <project>-test, <project>-prod<alias>-<purpose> or <alias>-dev<project>-pr-<number> when automation also guarantees cleanupKeep the name short enough to support resources with restrictive naming limits.
Use AZD commands rather than manual file editing:
azd env new <name>
azd env list
azd env select <name>
azd env set <key> <value>
azd env get-value <key>
azd env unset <key>
azd env refreshIn automation and potentially destructive operations, target the environment explicitly:
azd provision -e <environment> --no-prompt
azd deploy -e <environment> --no-prompt.azure files.azd env set for deployment-specific nonsecret settings.azd env refresh after another actor changes deployment outputs.Configure state.remote when teammates or automation need a shared AZD environment:
state:
remote:
backend: AzureBlobStorage
config:
accountName: <storage-account-name>
containerName: <project-container-name>Remote AZD state synchronizes .env and AZD config.json; it is separate from Terraform remote state. A Terraform project that collaborates through AZD can require both:
Protect both stores with least-privilege RBAC and appropriate data-protection settings.