Skip to content

feat(provisioner): Azure (azurerm) backend auto-provisioning - #2911

Merged
Andriy Knysh (aknysh) merged 13 commits into
mainfrom
aknysh/azure-backend-autoprovisioning
Aug 11, 2026
Merged

Andriy Knysh (aknysh) merged 13 commits into
mainfrom
aknysh/azure-backend-autoprovisioning

Conversation

@aknysh

@aknysh Andriy Knysh (aknysh) commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

what

Adds automatic provisioning for the azurerm Terraform state backend — the Azure counterpart to the existing S3 backend provisioner. When provision.backend.enabled: true on a component using an azurerm backend, Atmos creates the resource group (if missing), storage account, and blob container before terraform init, with opinionated secure defaults.

Previously, atmos terraform backend create returned create not implemented for backend type: azurerm and provision.backend.enabled silently skipped for Azure.

What gets created (hardcoded secure defaults)

  • Resource group in the identity's location (or reuses an existing group's location)
  • Storage account: StorageV2 / Standard_LRS, TLS 1.2 minimum, HTTPS-only, public blob access blocked
  • Entra ID hardening: shared-key access disabled when the backend sets use_azuread_auth: true
  • Blob versioning + 30-day soft delete (the S3-versioning analog)
  • Private container; Name + ManagedBy=Atmos tags

No lock resource is created — the azurerm backend serializes concurrent writes with native Azure Blob Storage blob leases (the DynamoDB / native-S3-locking analog, built into Blob Storage).

Design

  • Self-registers create/delete/exists/name into the shared backend registry via init(), so the before.terraform.init hook and atmos terraform backend create/delete pick up azurerm with no wiring changes to the hook or CLI.
  • A narrow azureBackendAPI interface hides the ARM SDK pollers behind synchronous methods for testability, mirroring the S3 client factory and the existing azurerm state-reader wrapper. A test-injectable client factory (SetAzureBackendClientFactory/ResetAzureBackendClientFactory) mirrors SetS3ClientFactory.
  • Location is sourced from the active Azure identity (or an existing resource group), never from the backend block — it is not a valid azurerm backend argument and Terraform would reject it in backend.tf.json.
  • Adds armresources + armstorage SDK deps (azcore/azidentity/azblob were already present).

Also fixes: azurerm backend init under Atmos-managed CLI auth

Field-testing the provisioner end-to-end surfaced a pre-existing bug that blocked azurerm backends whenever an Atmos profile was active. For CLI / device-code / interactive auth, Atmos exported both ARM_SUBSCRIPTION_ID and ARM_TENANT_ID to the Terraform subprocess. OpenTofu's azurerm backend authenticates via the Azure CLI and runs az account get-access-token --subscription <id> --tenant <id>, which the CLI rejects with Please specify only one of subscription and tenant, not both. It fails at argument validation — before the CLI even checks the session — so terraform init cannot list existing workspaces or read state at all:

Error: Failed to get existing workspaces: error listing blobs:
AzureCLICredential: ERROR: Please specify only one of subscription and tenant, not both

The tenant is now exported only for OIDC (service-principal / federated) auth, which needs it and does not shell out to the Azure CLI. On the CLI path only ARM_SUBSCRIPTION_ID is exported; the tenant is already fixed by the MSAL session Atmos seeds (and the active subscription), and the azurerm/azapi/azuread providers auto-detect it. oidc.go re-adds the tenant in its OIDC override, so service-principal auth is unchanged.

  • pkg/auth/cloud/azure/env.go: PrepareEnvironment gates the tenant export on UseOIDC.
  • pkg/auth/providers/azure/oidc.go: OIDC override re-adds ARM_TENANT_ID / AZURE_TENANT_ID.
  • Test updates assert the tenant is omitted on the CLI/device-code/interactive path and present for OIDC.

why

Brings Azure to feature parity with AWS for backend bootstrapping and eliminates the chicken-and-egg problem of needing remote state before Terraform can run — replacing the bespoke cold-start storage-account component teams currently hand-roll on Azure.

The CLI-auth fix is what makes the provisioned backend actually usable under Atmos-managed Azure auth: without it, terraform init against any azurerm backend fails while a profile is active.

references

  • New PRD: docs/prd/azurerm-backend-provisioner.md
  • Fix doc: docs/fixes/2026-08-11-azurerm-backend-cli-subscription-tenant-conflict.md
  • Mirrors: docs/prd/s3-backend-provisioner.md

test

  • Unit tests (pkg/provisioner/backend/azurerm_test.go, azurerm_wrappers_test.go): table-driven, mocked azureBackendAPI and Azure SDK fake servers — config extraction/precedence, use_azuread_auth parsing, full-create, resource-group reuse, existing-account warning, location-required error, every error path, existence checks, delete safety, registry wiring, and the ARM passthrough wrappers (404→exists mapping, poller completion, error propagation). 95.1% package coverage.
  • Auth fix tests (pkg/auth/cloud/azure/{env,setup}_test.go, pkg/auth/providers/azure/{cli,device_code,oidc}_test.go): both branches of the tenant gate verified — omitted for CLI/device-code/interactive, present for OIDC. env.go and oidc.go PrepareEnvironment are both 100% covered.
  • go build ./..., go vet, gofmt, and all pre-commit hooks (go-fumpt, golangci-lint, go.mod tidy) pass.

Note

The auto-provisioned account uses secure-but-simple defaults (Standard_LRS, Microsoft-managed keys, public network access with Entra ID/RBAC gating) intended for dev/test/bootstrap — not production. For production, import the resources into a managed module (e.g. Azure/avm-res-storage-storageaccount); the provisioner is idempotent, so provision.backend.enabled: true can be left in place.

@aknysh
Andriy Knysh (aknysh) requested a review from a team as a code owner August 10, 2026 01:24
@aknysh Andriy Knysh (aknysh) added the minor New features that do not break anything label Aug 10, 2026
@atmos-pro

atmos-pro Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions github-actions Bot added the size/l Large size PR label Aug 10, 2026
@aknysh Andriy Knysh (aknysh) self-assigned this Aug 10, 2026
@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 2 package(s) with unknown licenses.
See the Details below.

License Issues

go.mod

PackageVersionLicenseIssue Type
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources1.2.0NullUnknown License
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage/v44.1.0NullUnknown License
Allowed Licenses: MIT, MIT-0, Apache-2.0, BSD-2-Clause, BSD-2-Clause-Views, BSD-3-Clause, ISC, MPL-2.0, 0BSD, Unlicense, CC0-1.0, CC-BY-3.0, CC-BY-4.0, CC-BY-SA-3.0, Python-2.0, OFL-1.1, LicenseRef-scancode-generic-cla, LicenseRef-scancode-unknown-license-reference, LicenseRef-scancode-unicode, LicenseRef-scancode-google-patent-license-golang
Excluded from license check: pkg:golang/github.com/antlr4-go/antlr/v4, pkg:golang/github.com/google/cel-go, pkg:golang/golang.org/x/image, pkg:golang/modernc.org/libc, pkg:golang/github.com/opencontainers/go-digest, pkg:npm/pako, pkg:npm/sax

Scanned Files

  • go.mod

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 281f635c-e49e-43b6-95c5-98dabf43d494

📥 Commits

Reviewing files that changed from the base of the PR and between 9d18903 and 8192950.

📒 Files selected for processing (6)
  • docs/prd/azurerm-backend-provisioner.md
  • pkg/auth/providers/azure/oidc.go
  • pkg/provisioner/backend/azurerm.go
  • pkg/provisioner/backend/azurerm_test.go
  • pkg/provisioner/backend/azurerm_wrappers_test.go
  • website/docs/stacks/components/provision/backend.mdx
🚧 Files skipped from review as they are similar to previous changes (6)
  • pkg/auth/providers/azure/oidc.go
  • website/docs/stacks/components/provision/backend.mdx
  • docs/prd/azurerm-backend-provisioner.md
  • pkg/provisioner/backend/azurerm_wrappers_test.go
  • pkg/provisioner/backend/azurerm_test.go
  • pkg/provisioner/backend/azurerm.go

📝 Walkthrough

Walkthrough

Adds AzureRM backend provisioning with secure defaults, idempotent resource reuse, blob protection, lease-based locking, force-gated deletion, registry integration, tests, documentation, and Azure SDK dependencies. It also separates Azure tenant environment variables by authentication mode.

Changes

AzureRM backend lifecycle

Layer / File(s) Summary
Provisioning contract and configuration
docs/prd/azurerm-backend-provisioner.md, errors/errors.go, go.mod, NOTICE
Defines AzureRM configuration, security defaults, lifecycle rules, error sentinels, SDK dependencies, and license notices.
Resource provisioning and Azure clients
pkg/provisioner/backend/azurerm.go, pkg/provisioner/backend/azurerm_test.go, pkg/provisioner/backend/azurerm_wrappers_test.go
Adds registry handlers, validation, Azure client construction, resource provisioning, blob protection, private containers, and SDK wrapper tests.
Existence and forced deletion
pkg/provisioner/backend/azurerm.go, pkg/provisioner/backend/azurerm_delete.go, pkg/provisioner/backend/azurerm_test.go, pkg/provisioner/backend/azurerm_wrappers_test.go
Adds existence validation and force-gated storage-account deletion while retaining the resource group.
Documentation and roadmap
website/docs/stacks/components/provision/backend.mdx, website/blog/2026-08-09-azure-backend-provisioning.mdx, website/src/data/roadmap.js
Documents AzureRM setup, security settings, locking, commands, limitations, migration guidance, and roadmap status.

Azure authentication environment handling

Layer / File(s) Summary
Authentication-specific environment variables
pkg/auth/cloud/azure/env.go, pkg/auth/providers/azure/oidc.go
Keeps subscription variables for all modes, exports tenant variables for OIDC, and omits them for CLI or device-code authentication.
Authentication validation and fix documentation
pkg/auth/cloud/azure/*_test.go, pkg/auth/providers/azure/*_test.go, docs/fixes/2026-08-11-azurerm-backend-cli-subscription-tenant-conflict.md
Updates environment assertions for CLI and OIDC behavior and documents the subscription and tenant variable conflict.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BackendRegistry
  participant CreateAzurermBackend
  participant AzureBackendClient
  participant AzureResourceManager
  participant AzureBlobStorage
  BackendRegistry->>CreateAzurermBackend: invoke AzureRM backend creation
  CreateAzurermBackend->>AzureBackendClient: load Azure clients
  CreateAzurermBackend->>AzureResourceManager: ensure resource group and storage account
  CreateAzurermBackend->>AzureBlobStorage: apply protection and create private container
  AzureBlobStorage-->>CreateAzurermBackend: return provisioning result
Loading

Suggested labels: patch

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 49.02% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: automatic Azure azurerm backend provisioning.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aknysh/azure-backend-autoprovisioning

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (3)
pkg/provisioner/backend/azurerm_test.go (2)

286-330: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the storage account tags in the full-create test.

The mock captures createdAccountParams, and the PRD states Name=<account> and ManagedBy=Atmos are hardcoded defaults. The test does not check them, so a regression in azureBackendTags would pass. The captured params make this a two-line assertion.

💚 Proposed test addition
 	require.NotNil(t, mock.createdAccountParams)
 	assert.Equal(t, "centralus", mock.createdAccountParams.location, "account created in identity location")
 	assert.True(t, mock.createdAccountParams.disableSharedKey, "shared key disabled when use_azuread_auth is true")
+	require.NotNil(t, mock.createdAccountParams.tags["Name"])
+	require.NotNil(t, mock.createdAccountParams.tags["ManagedBy"])
+	assert.Equal(t, "stcwtfstate", *mock.createdAccountParams.tags["Name"])
+	assert.Equal(t, "Atmos", *mock.createdAccountParams.tags["ManagedBy"])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provisioner/backend/azurerm_test.go` around lines 286 - 330, Extend
TestCreateAzurermBackend_FullCreate to assert the captured
mock.createdAccountParams tags include the hardcoded defaults Name=stcwtfstate
and ManagedBy=Atmos, alongside the existing account parameter assertions.

486-507: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the sentinel in the "account check error" case after the wrapping fix.

This case only calls require.Error. It passes with any error, including the raw ARM error. Once AzurermBackendExists wraps the failure (see the comment on pkg/provisioner/backend/azurerm.go lines 240-248), add assert.ErrorIs(t, err, errUtils.ErrCheckStorageAccountExist) so the test pins the contract. Every other error test in this file asserts a sentinel.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provisioner/backend/azurerm_test.go` around lines 486 - 507, Update the
“account check error” case in the AzurermBackendExists table test to assert that
the returned error matches errUtils.ErrCheckStorageAccountExist using
assert.ErrorIs, while retaining the existing require.Error check and behavior
for other cases.
pkg/provisioner/backend/azurerm.go (1)

255-273: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Return the sentinels directly instead of fmt.Errorf("%w", err).

fmt.Errorf("%w", errUtils.ErrX) adds no context. It only allocates a wrapper with an identical message. Either return the sentinel, or use errUtils.Build to attach a hint that names the missing key, which is more useful to the user.

♻️ Proposed refactor
 	storageAccount, ok := backendConfig["storage_account_name"].(string)
 	if !ok || storageAccount == "" {
-		return nil, fmt.Errorf("%w", errUtils.ErrStorageAccountRequired)
+		return nil, errUtils.Build(errUtils.ErrStorageAccountRequired).
+			WithHint("Set `backend.storage_account_name` in the component configuration").
+			Err()
 	}

Apply the same pattern to the container_name, resource_group_name, and subscription checks.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provisioner/backend/azurerm.go` around lines 255 - 273, Update the
validation checks in the backend configuration flow to return the relevant
errUtils sentinel directly instead of wrapping it with fmt.Errorf("%w", ...).
Apply this to storage_account_name, container_name, resource_group_name, and the
subscriptionID check, preserving the existing validation and return behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@go.mod`:
- Around line 482-483: Update the Azure SDK dependencies in go.mod to use the
current armstorage/v4 module at v4.1.0 instead of the stale armstorage v1.8.1
entry, and remove armresources and armstorage entries from go.mod and go.sum
when no code imports them. Ensure the resulting dependency files contain only
required, correctly versioned direct dependencies.

In `@pkg/provisioner/backend/azurerm_delete.go`:
- Around line 40-68: Remove the direct ui.Info and ui.Successf calls from the
deletion callback in DeleteBackendWithParams, including the visible Azure
deletion messages. Defer or collect these messages so they are emitted only
after spinner execution completes, preserving the existing message content and
deletion flow; apply the same pattern to DeleteS3Backend.

In `@pkg/provisioner/backend/azurerm.go`:
- Around line 240-248: Update AzurermBackendExists in
pkg/provisioner/backend/azurerm.go (lines 240-248) to wrap storageAccountExists
failures with errUtils.ErrCheckStorageAccountExist and containerExists failures
with errUtils.ErrCheckContainerExist, including the storage account, resource
group, and container context. In pkg/provisioner/backend/azurerm_test.go (lines
486-507), extend the “account check error” case with an ErrorIs assertion for
errUtils.ErrCheckStorageAccountExist.

In `@website/docs/stacks/components/provision/backend.mdx`:
- Line 210: Update the documentation for the use_azuread_auth setting to state
that it disables shared-key access only for newly created storage accounts,
because the auto-provision hook skips existing complete backends; direct users
to separately harden existing storage accounts.

In `@website/src/data/roadmap.js`:
- Line 212: Update the benefits text in the roadmap entry for “Azure (`azurerm`)
backend auto-provisioning” to say “workflow AWS users already had,” removing
“Azure” from that comparison while leaving the rest of the description
unchanged.

---

Nitpick comments:
In `@pkg/provisioner/backend/azurerm_test.go`:
- Around line 286-330: Extend TestCreateAzurermBackend_FullCreate to assert the
captured mock.createdAccountParams tags include the hardcoded defaults
Name=stcwtfstate and ManagedBy=Atmos, alongside the existing account parameter
assertions.
- Around line 486-507: Update the “account check error” case in the
AzurermBackendExists table test to assert that the returned error matches
errUtils.ErrCheckStorageAccountExist using assert.ErrorIs, while retaining the
existing require.Error check and behavior for other cases.

In `@pkg/provisioner/backend/azurerm.go`:
- Around line 255-273: Update the validation checks in the backend configuration
flow to return the relevant errUtils sentinel directly instead of wrapping it
with fmt.Errorf("%w", ...). Apply this to storage_account_name, container_name,
resource_group_name, and the subscriptionID check, preserving the existing
validation and return behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 94ed3010-3da4-4b62-b132-0c7901d2d8ba

📥 Commits

Reviewing files that changed from the base of the PR and between 1107de3 and 79eb955.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (9)
  • docs/prd/azurerm-backend-provisioner.md
  • errors/errors.go
  • go.mod
  • pkg/provisioner/backend/azurerm.go
  • pkg/provisioner/backend/azurerm_delete.go
  • pkg/provisioner/backend/azurerm_test.go
  • website/blog/2026-08-09-azure-backend-provisioning.mdx
  • website/docs/stacks/components/provision/backend.mdx
  • website/src/data/roadmap.js

Comment thread go.mod Resolved
Comment thread pkg/provisioner/backend/azurerm.go Resolved
Comment thread website/src/data/roadmap.js Resolved
@codecov

codecov Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.73371% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.85%. Comparing base (21c5899) to head (8192950).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/provisioner/backend/azurerm.go 97.36% 4 Missing and 4 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2911      +/-   ##
==========================================
+ Coverage   82.83%   82.85%   +0.01%     
==========================================
  Files        1866     1868       +2     
  Lines      181277   181624     +347     
==========================================
+ Hits       150160   150481     +321     
- Misses      23313    23328      +15     
- Partials     7804     7815      +11     
Flag Coverage Δ
unittests 82.85% <97.73%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
errors/errors.go 100.00% <ø> (ø)
pkg/auth/cloud/azure/env.go 100.00% <100.00%> (ø)
pkg/auth/providers/azure/oidc.go 91.07% <100.00%> (-0.04%) ⬇️
pkg/provisioner/backend/azurerm_delete.go 100.00% <100.00%> (ø)
pkg/provisioner/backend/azurerm.go 97.36% <97.36%> (ø)

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 10, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/provisioner/backend/azurerm_wrappers_test.go (1)

66-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use table-driven tests for repeated scenarios.

These tests define multiple behavior cases with separate subtests. Use one table and one subtest loop per API method.

  • pkg/provisioner/backend/azurerm_wrappers_test.go#L66-L104: convert resource-group existence cases to a table.
  • pkg/provisioner/backend/azurerm_wrappers_test.go#L106-L131: convert resource-group creation cases to a table.
  • pkg/provisioner/backend/azurerm_wrappers_test.go#L167-L224: convert storage-account creation cases to a table.
  • pkg/provisioner/backend/azurerm_wrappers_test.go#L226-L254: convert blob data-protection cases to a table.
  • pkg/provisioner/backend/azurerm_wrappers_test.go#L290-L315: convert container creation cases to a table.
  • pkg/provisioner/backend/azurerm_wrappers_test.go#L317-L339: convert storage-account deletion cases to a table.

As per coding guidelines, “Use table-driven tests for testing multiple scenarios in Go.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provisioner/backend/azurerm_wrappers_test.go` around lines 66 - 104,
Convert the repeated scenarios in TestAzureBackendClient_ResourceGroupExists and
the tests at pkg/provisioner/backend/azurerm_wrappers_test.go lines 106-131,
167-224, 226-254, 290-315, and 317-339 into table-driven tests with one subtest
loop per API method; preserve each scenario’s existing setup, assertions, and
error behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/provisioner/backend/azurerm_wrappers_test.go`:
- Around line 173-180: The Azure fake provisioning handlers do not fully verify
required request fields. In
pkg/provisioner/backend/azurerm_wrappers_test.go:173-180, extend the
storage-account assertions to cover HTTPS-only access, public-blob access, and
Atmos tagging; in pkg/provisioner/backend/azurerm_wrappers_test.go:110-113,
assert the resource-group Tags. Preserve the existing location, SKU, TLS, and
shared-key assertions while validating the expected security defaults and tags.
- Around line 231-241: Extend the applyBlobDataProtection test’s
SetServiceProperties responder to capture
params.BlobServiceProperties.DeleteRetentionPolicy.Enabled, then assert the
captured nullable flag is present and true alongside the existing retention-days
assertions. Keep the current versioning and retention validation unchanged.

---

Nitpick comments:
In `@pkg/provisioner/backend/azurerm_wrappers_test.go`:
- Around line 66-104: Convert the repeated scenarios in
TestAzureBackendClient_ResourceGroupExists and the tests at
pkg/provisioner/backend/azurerm_wrappers_test.go lines 106-131, 167-224,
226-254, 290-315, and 317-339 into table-driven tests with one subtest loop per
API method; preserve each scenario’s existing setup, assertions, and error
behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c668d70d-79d5-4916-a4ee-a96f50026f2c

📥 Commits

Reviewing files that changed from the base of the PR and between 92a083a and 27193bd.

📒 Files selected for processing (2)
  • pkg/provisioner/backend/azurerm_test.go
  • pkg/provisioner/backend/azurerm_wrappers_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/provisioner/backend/azurerm_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/provisioner/backend/azurerm_wrappers_test.go`:
- Line 70: Update the inline comments on the code field at
pkg/provisioner/backend/azurerm_wrappers_test.go:70-70 and the wantSharedKeyNil
field at pkg/provisioner/backend/azurerm_wrappers_test.go:188-188 so each
comment ends with a period.
- Line 381: Replace the ad hoc errors.New("cred boom") in the injected Azure
credential failure path with a distinct repository-level static error from
errors/errors.go. Reuse an existing suitable error or add a dedicated Azure
client initialization error, keeping it separate from
errUtils.ErrLoadAzureConfig so the wrapper test continues to validate the
intended failure.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 354838c1-1c4c-487d-8f78-4dbf2f62084e

📥 Commits

Reviewing files that changed from the base of the PR and between 92a083a and f5e68f1.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • NOTICE
  • errors/errors.go
  • go.mod
  • pkg/provisioner/backend/azurerm_test.go
  • pkg/provisioner/backend/azurerm_wrappers_test.go
  • website/src/data/roadmap.js
🚧 Files skipped from review as they are similar to previous changes (5)
  • NOTICE
  • website/src/data/roadmap.js
  • errors/errors.go
  • pkg/provisioner/backend/azurerm_test.go
  • go.mod

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/auth/cloud/azure/env_test.go (1)

70-77: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Test removal of inherited tenant variables.

This case asserts that tenant variables are absent, but inputEnv does not contain either tenant variable. The test passes if the clearing logic stops removing inherited tenant values. Add AZURE_TENANT_ID and ARM_TENANT_ID to this case's inputEnv.

Proposed fix.
 inputEnv: map[string]string{
     "AZURE_CLIENT_ID":               "conflicting-client-id",
     "AZURE_CLIENT_SECRET":           "conflicting-secret",
     "AZURE_CLIENT_CERTIFICATE_PATH": "/path/to/cert",
+    "AZURE_TENANT_ID":               "conflicting-tenant-id",
     "ARM_CLIENT_ID":                 "conflicting-arm-client",
     "ARM_CLIENT_SECRET":             "conflicting-arm-secret",
+    "ARM_TENANT_ID":                 "conflicting-arm-tenant-id",
     "HOME":                          "/home/user",
 },

As per coding guidelines, "Every new feature must include comprehensive unit tests targeting >80% code coverage for all packages."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/auth/cloud/azure/env_test.go` around lines 70 - 77, Update the test case
containing expectedMissing in the environment-clearing tests so its inputEnv
explicitly includes both AZURE_TENANT_ID and ARM_TENANT_ID with inherited
values. Keep those variables in expectedMissing to verify the clearing logic
removes them.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/fixes/2026-08-11-azurerm-backend-cli-subscription-tenant-conflict.md`:
- Around line 10-13: Add the text language identifier to the fenced error-output
block containing the AzureCLICredential message, changing the opening fence to
use text while preserving the output content.

---

Outside diff comments:
In `@pkg/auth/cloud/azure/env_test.go`:
- Around line 70-77: Update the test case containing expectedMissing in the
environment-clearing tests so its inputEnv explicitly includes both
AZURE_TENANT_ID and ARM_TENANT_ID with inherited values. Keep those variables in
expectedMissing to verify the clearing logic removes them.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 693f1424-8438-40f1-87be-3a0d708c2af1

📥 Commits

Reviewing files that changed from the base of the PR and between f5e68f1 and ce38ac3.

📒 Files selected for processing (8)
  • docs/fixes/2026-08-11-azurerm-backend-cli-subscription-tenant-conflict.md
  • pkg/auth/cloud/azure/env.go
  • pkg/auth/cloud/azure/env_test.go
  • pkg/auth/cloud/azure/setup_test.go
  • pkg/auth/providers/azure/cli_test.go
  • pkg/auth/providers/azure/device_code_test.go
  • pkg/auth/providers/azure/oidc.go
  • pkg/provisioner/backend/azurerm_wrappers_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/provisioner/backend/azurerm_wrappers_test.go

@aknysh

Copy link
Copy Markdown
Member Author

CodeRabbit (@coderabbitai) full review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
pkg/auth/providers/azure/oidc.go (1)

543-551: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Pass the OIDC mode to the shared environment helper.

oidcProvider.PrepareEnvironment calls azureCloud.PrepareEnvironment without UseOIDC: true. The helper therefore enters the CLI branch, sets ARM_USE_CLI, and logs a CLI-auth message before this method deletes the value and restores the OIDC tenant variables. Pass UseOIDC: true in azureCloud.PrepareEnvironmentConfig and remove this repair block. This keeps authentication-mode behavior in one place.

Suggested alignment.
 		Location:          p.location,
 		CloudEnvironment:  p.cloudEnv.Name,
+		UseOIDC:           true,
 	})
 
-	// Override ARM_USE_CLI to use OIDC instead.
-	delete(result, "ARM_USE_CLI")
-	result["ARM_USE_OIDC"] = "true"
-
-	// Export the tenant for OIDC. The shared CLI-path env preparation deliberately omits it (it
-	// would make the azurerm backend's Azure CLI credential pass both --subscription and --tenant,
-	// which the CLI rejects). OIDC (service-principal / federated) auth needs the tenant explicitly
-	// and does not shell out to the Azure CLI, so there is no such conflict here.
-	if p.tenantID != "" {
-		result["ARM_TENANT_ID"] = p.tenantID
-		result["AZURE_TENANT_ID"] = p.tenantID
-	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/auth/providers/azure/oidc.go` around lines 543 - 551, Update
oidcProvider.PrepareEnvironment to pass UseOIDC: true in the
azureCloud.PrepareEnvironmentConfig call, ensuring the shared helper follows the
OIDC path directly. Remove the subsequent ARM_USE_CLI cleanup and manual
ARM_TENANT_ID/AZURE_TENANT_ID repair block, leaving authentication-mode
environment setup centralized in azureCloud.PrepareEnvironment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/prd/azurerm-backend-provisioner.md`:
- Around line 251-254: Update docs/prd/azurerm-backend-provisioner.md lines
251-254 to reference azurerm_wrappers_test.go instead of claiming ARM SDK
wrappers are only integration-tested against real Azure, and add that test file
to the package structure block at lines 199-204. Update the
TestNewAzureBackendClient comment in pkg/provisioner/backend/azurerm_test.go
lines 608-614 to reference azurerm_wrappers_test.go rather than stating wrappers
are exercised only against real Azure.

In `@pkg/provisioner/backend/azurerm.go`:
- Around line 541-556: Update applyBlobDataProtection to read the existing blob
service properties before calling SetServiceProperties, and use the greater of
blobSoftDeleteRetentionDays and each existing blob/container delete-retention
period. Preserve longer configured periods while continuing to enable versioning
and both policies.

In `@website/docs/stacks/components/provision/backend.mdx`:
- Around line 192-196: Update the “Entra ID hardening” documentation to clarify
that Atmos preserves the existing shared-key setting for pre-existing storage
accounts, while CreateAzurermBackend still processes incomplete backends by
applying blob versioning and soft delete before creating the missing container.

---

Nitpick comments:
In `@pkg/auth/providers/azure/oidc.go`:
- Around line 543-551: Update oidcProvider.PrepareEnvironment to pass UseOIDC:
true in the azureCloud.PrepareEnvironmentConfig call, ensuring the shared helper
follows the OIDC path directly. Remove the subsequent ARM_USE_CLI cleanup and
manual ARM_TENANT_ID/AZURE_TENANT_ID repair block, leaving authentication-mode
environment setup centralized in azureCloud.PrepareEnvironment.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a049c26b-e7e4-4cc9-8577-ab806318dd61

📥 Commits

Reviewing files that changed from the base of the PR and between 21c5899 and 9d18903.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (18)
  • NOTICE
  • docs/fixes/2026-08-11-azurerm-backend-cli-subscription-tenant-conflict.md
  • docs/prd/azurerm-backend-provisioner.md
  • errors/errors.go
  • go.mod
  • pkg/auth/cloud/azure/env.go
  • pkg/auth/cloud/azure/env_test.go
  • pkg/auth/cloud/azure/setup_test.go
  • pkg/auth/providers/azure/cli_test.go
  • pkg/auth/providers/azure/device_code_test.go
  • pkg/auth/providers/azure/oidc.go
  • pkg/provisioner/backend/azurerm.go
  • pkg/provisioner/backend/azurerm_delete.go
  • pkg/provisioner/backend/azurerm_test.go
  • pkg/provisioner/backend/azurerm_wrappers_test.go
  • website/blog/2026-08-09-azure-backend-provisioning.mdx
  • website/docs/stacks/components/provision/backend.mdx
  • website/src/data/roadmap.js

Comment thread docs/prd/azurerm-backend-provisioner.md Resolved
Comment thread pkg/provisioner/backend/azurerm.go Resolved
@aknysh
Andriy Knysh (aknysh) added this pull request to the merge queue Aug 11, 2026
@atmos-pro

atmos-pro Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

Merged via the queue into main with commit 3c87e0a Aug 11, 2026
84 checks passed
@aknysh
Andriy Knysh (aknysh) deleted the aknysh/azure-backend-autoprovisioning branch August 11, 2026 16:31
@atmos-pro

atmos-pro Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

Igor Rodionov (goruha) added a commit that referenced this pull request Aug 11, 2026
…into 1199-pro-exec-metadata

* '1199-pro-exec-metadata' of github.com:cloudposse/atmos:
  Add task-runner dependencies, freshness checks, and preconditions to custom commands and workflows (#2882)
  feat(provisioner): Azure (azurerm) backend auto-provisioning (#2911)
  fix: preserve trailing newlines in text-based 3-way merges (#2891)
  fix(scaffold): preserve source in scaffold config (#2869)
  fix(deps): update github.com/epiclabs-io/diff3 digest to 3b16698 (#2917)
  fix(deps): update kubernetes monorepo to v0.36.3 (#2918)
@github-actions

Copy link
Copy Markdown

These changes were released in v1.226.0-rc.5.

This branch was successfully deployed

1 active deployment
preview — 81929509 Deployed Aug 11, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features that do not break anything size/l Large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants