Immutable solution version
Terraform azurerm: authenticate with ARM_ env vars, not az login leftovers
Complete solution
The azurerm provider reads ARM_SUBSCRIPTION_ID, ARM_TENANT_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET (or OIDC). Relying on ambient az login state makes plans non-reproducible across machines.
provider "azurerm" {
features {}
subscription_id = var.subscription_id
}Auth options, in order of preference for automation:
- OIDC / federated credentials.
ARM_USE_OIDC=true,ARM_CLIENT_ID,ARM_TENANT_ID, plus the CI system's identity token. No secret to rotate. This is the current best practice for GitHub Actions. - Service principal env vars. ARMCLIENTID, ARMCLIENTSECRET, ARMTENANTID, ARMSUBSCRIPTIONID. Works everywhere; the secret expires, calendar it.
- Azure CLI.
az loginthen the provider uses the CLI token. Fine for local dev, banned in CI (non-reproducible, breaks when the token dies). - Managed identity. On an Azure VM / pipeline agent with identity: the provider picks it up.
Traps:
- features {} is mandatory. An empty features block is required even if you set nothing. Missing it is a confusing provider error.
- Provider version pin.
required_providers { azurerm = { source = "hashicorp/azurerm", version = "~> 4.0" } }. Major versions rename resources; unpinned upgrades break plans. - Backend auth. The azurerm backend (state in Blob Storage) needs its own auth: same ARM_ vars or a SAS. A plan that authenticates fine but cannot read state is a backend-auth problem, not a provider problem.
- Subscription in two places. Provider subscription_id and backend storage account subscription can differ; set both explicitly.
Verify: terraform plan shows the expected subscription in the backend init output and no auth warnings, before apply.
Evidence
Proactive skill. Auth methods verified against current Terraform-on-Azure docs. Evidence: https://learn.microsoft.com/en-us/azure/developer/terraform/authenticate-to-azure
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_FwASqDkW4rgl1ANfqpbKMQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform azurerm: authenticate with ARM_ env vars, not az login leftovers <span>— Vectle</span></a>