A Storage Account Has Management and Data APIs
A storage account is two services behind one name. The ARM resource is created and configured through the management plane; the bytes are read and written through the account's blob endpoint on the data plane. With Terraform 1.17.1 and hashicorp/azurerm 5.13.0, both are reachable from one root, but they authorize differently.
A management role is not checked on the blob request. Contributor can delete the account and still receive 403 when it reads a blob directly. That does not make it harmless, because it can re-enable Shared Key and read the key, so management scope is data access in waiting.
Storage Account Contributor is narrower but still powerful. It manages the account and its keys, not blob content. It is not a substitute for a blob data role, and it is too broad for a content pipeline.
Scope decides how far a data role reaches. A blob role assigned at subscription or account scope applies to every container; assigned at container scope it applies to one namespace. Start at the container and widen only when a shared platform requires it.
The endpoint chooses the token audience. An ARM call to management.azure.com carries a management token; a blob call to the account host needs a storage-scoped token. Presenting one where the other is expected fails before any role is evaluated.
Shared Key is the exception that hides the model. A caller with the account key signs the request and receives whatever the key allows, with no data-plane role and no useful principal in the audit log. That is why disabling the key forced a redesign rather than a permission tweak.
Terraform sits on both planes. The provider creates the account through ARM and, with storage_use_azuread enabled, manages containers and blobs through the data plane. Without that switch it falls back to Shared Key.
Read the status code before changing a role. A 403 naming AuthorizationPermissionMismatch is missing data-plane RBAC; a bare 403 is usually a network rule or private endpoint problem.
Figure 1 separates the two planes and the three ways a blob request can authenticate.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
P["Pipeline or operator"] --> CP["ARM control plane
management.azure.com"]
CP --> ACC["Storage account
create, network, encryption"]
CP --> RBAC["Role assignments
management and data scopes"]
P --> DP["Blob data plane
account.blob.core.windows.net"]
DP --> AAD["Entra ID token
storage audience"]
DP --> KEY["Shared Key signature
account key"]
DP --> SAS["User delegation SAS
signed by Entra ID"]
AAD --> GATE{"Data role on
container or account?"}
GATE -->|"yes"| OK["List, read, write blob"]
GATE -->|"no"| NO["403
AuthorizationPermissionMismatch"]
KEY --> OK
SAS --> OK
ACC -.->|"configures, does not grant bytes"| DP
RBAC -.->|"grants data actions"| GATE
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class P,CP,DP primary;
class ACC,RBAC,AAD,SAS secondary;
class GATE,OK ok;
class KEY warn;
class NO danger;
The useful summary is one sentence. An account-level role decides whether you can manage the account; a blob role decides whether you can read a single object.
The diagram is a map of repairs, not a hierarchy. If the account is visible but the container is not, the missing grant is on the data plane; if the endpoint does not resolve, no role will help.
Configure Blob Access, Encryption and Retention Deliberately
Encryption at rest is automatic; key ownership is the decision. Every storage account encrypts with AES-256, and Microsoft-managed keys are the default. A customer-managed key in Key Vault adds a second authorization system and a second dependency.
Infrastructure encryption is a creation-time choice. infrastructure_encryption_enabled applies a second layer of encryption and cannot be changed later. Decide at bootstrap, because recreating a state account later is a migration.
Shared Key is the setting most often left on. It grants full account access to anyone holding the key, bypasses RBAC and rotation, and makes every leaked connection string an incident. Disable it and turn on default_to_oauth_authentication so portal sessions start with Entra ID.
Disabling Shared Key changes the provider's behavior too. Storage resources fall back to Shared Key unless storage_use_azuread is set, so the same apply that hardens the account can break container management. Change both in one review.
Public access has an account gate and a container gate. allow_nested_items_to_be_public defaults to false in provider 5.x, and the container access type defaults to private. Keep both private; a container set to blob or container access is a deliberate public decision, not a default.
Versioning, soft delete and point-in-time restore are different promises. Versioning keeps every overwrite, soft delete keeps deleted blobs and containers for a window, and point-in-time restore needs versioning, change feed and soft delete together. Enabling one does not enable the others.
Retention must outlive detection, not the sprint. A seven-day soft delete window cannot recover corruption found on day ten. Set the window from how long a bad write can stay unnoticed, then test a restore inside that window.
Lifecycle rules are destructive automation. A delete rule without a prefix or tag filter applies to everything in the account, including state and backups. Scope each rule, exclude the state container, and review the first execution.
A customer-managed key is an availability dependency. Losing the Key Vault key, its permissions or the vault itself makes the account unreadable even though the bytes still exist. Give the vault soft delete and purge protection, and give it an owner separate from the storage team.
Encryption scopes move the key decision down to a container. A scope can bind a container or blob to a separate customer-managed key, which is how one account serves tenants with different keys. The scope is a resource with its own lifecycle, not an account-wide switch.
Immutability is retention that no role can shorten. A time-based immutability policy can be locked, and then even an account owner cannot delete the protected versions before expiry through the data plane. It is the right control for records and the wrong control for a lab.
Figure 2 follows the decisions and the failure branches they create.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["Account baseline
TLS 1.2, private endpoint"] --> B{"Shared Key enabled?"}
B -->|"yes"| C["Account key bypasses RBAC
and hides the caller"]
B -->|"no"| D["Entra ID or user delegation SAS"]
D --> E{"Blob data role
at container scope?"}
E -->|"no"| F["403
AuthorizationPermissionMismatch"]
E -->|"yes"| G["Read and write allowed"]
C --> H{"Versioning and
soft delete enabled?"}
G --> H
H -->|"no"| I["Overwrite or delete
is permanent"]
H -->|"yes"| J["Previous version or
soft-deleted blob retained"]
J --> K{"Retention longer than
detection time?"}
K -->|"no"| L["Recovery window closes
before the incident is found"]
K -->|"yes"| M["Restore is possible
and must be rehearsed"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class A,B,D,E,H,K primary;
class C,G,J secondary;
class M ok;
class F,L danger;
class I warn;
The quiet failure is the left branch. Shared Key and a short retention window both look healthy in a plan, because neither changes an attribute that a plan diff can question. Only a restore drill and an audit-log review expose them.
Keep Container Provisioning and Bulk Content Separate
Containers are infrastructure; objects are content. Terraform should own the container, its access level, encryption scope and immutability policy. It should not enumerate a release, because a release changes for reasons that have nothing to do with infrastructure review.
The container resource is a data-plane call in disguise. When storage_use_azuread is on, creating a container needs a blob data role, not just Contributor on the account.
Changing the access level still uses Shared Key. The provider documents that an update to container_access_type always authenticates with Shared Key, even when AAD is enabled elsewhere. With Shared Key disabled, that update fails; decide container access at creation.
Do not use a blob resource for a release. azurerm_storage_blob gives every object its own address, so a thousand files become a thousand plan entries, a slow state and a delete path nobody can review.
Bulk content belongs to a data tool. AzCopy, an SDK or the application writes objects with a credential scoped to one container and one prefix. None of those bytes enter Terraform state.
Publish under an immutable prefix. Write each release to a new prefix, verify checksums, then move the manifest that readers use. A rollback becomes a manifest change instead of a re-upload.
Container names are the namespace; object keys are the content contract. A prefix convention belongs in documentation and application code, not in a Terraform resource per file. Changing the convention later is a data migration, not a rename.
Deletion is a separate reviewed job. A mirror sync with delete enabled removes destination objects the source no longer has, including another team's content. Make deletion opt-in, dry-run it, and record object counts before and after.
Use three identities, not one. The infrastructure identity configures accounts and containers, the release identity writes one prefix, and the runtime identity reads what it serves. A single identity with all three turns every pipeline into a potential destroyer.
Bootstrap a Private State Container with a Recovery Owner
The backend is not the provider. backend "azurerm" is initialized before any provider block, and it talks to the blob data plane directly. The provider's storage_use_azuread setting does not configure it.
Bootstrap has a chicken-and-egg problem. The root that uses the state account cannot create it. Use a small bootstrap root with local state, or a reviewed CLI step, then bring the account under the bootstrap root with an import and lock it down.
Authenticate the backend with Entra ID. Set use_azuread_auth and use_oidc, then grant the backend identity Storage Blob Data Contributor on the state container. It needs no management role unless endpoint lookup is enabled.
Locking is a blob lease, not a database row. One writer holds the lease on one state blob; a second run waits or fails with a lock error. Use a lock timeout in CI, and reserve force-unlock for a confirmed dead run.
Use one key per root and environment. The blob key is the state's identity, and reusing a blob key means two roots share one serial and one lock. A container-scoped role limits the damage of a misconfigured pipeline.
The recovery owner is a group, not a person. That group holds Storage Blob Data Owner on the container, Contributor on the account and crypto rights on the Key Vault when CMK is used. It restores versions, breaks stale leases and pushes state after an incident.
Private networking is part of the bootstrap. With public access disabled, a private endpoint for the blob subresource and a linked private DNS zone are required before the first init. A runner that cannot resolve the privatelink name fails before authentication.
Versioning is the backup; soft delete is the undelete. Enable both on the state account. The backend's snapshot option takes an extra snapshot before use, but restoring it is still a manual, reviewed action.
A resource lock protects the account, not the blob. CanNotDelete stops a management-plane delete of the account or container, while a data-plane delete of a state blob still succeeds. The recovery controls that matter are versioning and soft delete.
The table compares the backend's authentication choices by what they require and what they hide.
| Backend auth | What Terraform sends | Role required | Trade-off |
|---|---|---|---|
| Entra ID with OIDC | Short-lived token, then a blob lease | Storage Blob Data Contributor on the container | No stored secret, but federation and a data role must exist |
| Entra ID with Azure CLI | Cached CLI token | Storage Blob Data Contributor on the container | Only for a developer workstation, and the token expires |
| Access key | Account key signature | None, because the key is the authority | Grants the whole account and stops working when Shared Key is off |
| SAS token | Signed URL with expiry | Write and list on the state container | Secret to store and rotate, and no principal in the audit log |
| Access key lookup | ARM reads the key, then signs with it | Reader plus Storage Account Key Operator on the account | Management role can exfiltrate keys, so avoid it for CI |
Figure 3 shows the bootstrap hand-off and the two recovery actions that keep a bad apply from becoming a permanent outage.
Read the table as an authorization decision. A key or SAS removes the need for a data role and also removes the identity from the audit trail. Entra ID with OIDC is the only row that scales to ephemeral CI without a stored secret.
Verify Access from CI and Rehearse a Snapshot Restore
A green init proves the backend, not the data path. Init can succeed through a cached token while the CI identity still cannot read a content container. Test both paths with the same identity the pipeline uses.
Propagation is part of the test. A new role assignment can take minutes to appear in the data plane, and a private endpoint's DNS record can lag the endpoint. Re-run the same command after a short wait before changing the role.
A version restore returns bytes, not a valid plan. A restored blob can carry an older serial and miss resources created after that version, so the next apply may try to create duplicates. Pull the restored state, compare it with the last known good plan, and reconcile before applying.
Verify Access from CI and Rehearse a Snapshot Restore
Execution status: design-only. These steps were not run against a live subscription. Use a disposable resource group and keep the command output as evidence.
Prerequisites. Terraform 1.17.1 with hashicorp/azurerm 5.13.0, a subscription, a bootstrap identity that can create resource groups and role assignments, and a separate CI identity. Choose a unique name suffix.
- In the bootstrap root with local state, create the account and
tfstatecontainer with TLS 1.2, Shared Key off, public access off, versioning on and 30-day soft delete. - Grant the CI identity Storage Blob Data Contributor on the container, then confirm the assignment is scoped to the container rather than the subscription.
- In the application root, run
terraform initwith the AAD backend and a per-root blob key. Confirm it succeeds without an account key and that the state blob appears. - Start an apply and leave it at the approval prompt. Run a plan from a second terminal; it should report a state lock instead of writing to the same state.
- Kill the first process without approving, confirm that no Terraform process is alive, then force-unlock with the reported lock ID and run a fresh plan.
- Upload one test blob, overwrite it, delete it, list versions, then copy the previous version over the base blob and compare checksums.
- Add the private endpoint and DNS zone, then disable public network access. Resolve the account host from the CI runner and from outside the network. Expect a private address inside and a 403 outside.
- Pull a state backup, delete the state blob, restore its previous version, compare the serial, and plan again. With the backend snapshot option on, repeat the restore from the pre-run snapshot.
Expected observation. Init uses an Entra ID token, the lock appears as a lease, and the restored state keeps its lineage and serial. DNS and RBAC failures are time-based: the same command can succeed without a configuration change.
Failure checks. A 403 with AuthorizationPermissionMismatch means the data role is missing or not propagated; a 403 without a role message points at network rules. A lock that does not clear usually means a live run, while an expired lease releases on its own.
Cost and cleanup. State blobs and versions cost cents, but private endpoint hours and retained versions accumulate. Destroy the application root, then the bootstrap root, remove the DNS zone link, and confirm no state blob or version remains.
References (checked 6 November 2026): azurerm backend, storage account, storage container, and blob data roles.
Next in the Series
In Azure Data Services: SQL, PostgreSQL and Cosmos DB Lifecycles, we'll explore Review database availability, throughput, secrets and recovery without conflating infrastructure and application schemas.