Skip to content

feat: add tfstate_enabled toggle to gate module-managed state backend - #4

Merged
danielgines merged 1 commit into
masterfrom
feat/tfstate-enabled-toggle
Jun 1, 2026
Merged

feat: add tfstate_enabled toggle to gate module-managed state backend#4
danielgines merged 1 commit into
masterfrom
feat/tfstate-enabled-toggle

Conversation

@danielgines

Copy link
Copy Markdown
Member

Summary

Adds var.tfstate_enabled (default true) to gate the module-managed Terraform state backend, so a workload can point its backend at an external, pre-provisioned storage account (e.g. a central bootstrap layer) instead of always creating its own — eliminating an orphaned tfstate storage account per cluster.

Motivation

When a downstream repo sets its backend "azurerm" to a pre-declared container in a shared bootstrap storage account, the module still created its own rg-<base>-tfstate + storage account + container unconditionally (no toggle existed up to v3.4.1). That storage account was never used as a backend and sat orphaned. This adds the missing switch.

Changes

  • New var.tfstate_enabled (bool, default true).
  • tfstate.tf: count on azurerm_resource_group.tfstate, azurerm_storage_account.tfstate, azurerm_storage_container.tfstate, azurerm_role_assignment.tfstate_deployer; internal refs indexed [0]. The tfstate private endpoint now requires tfstate_enabled && tfstate_private_endpoint_enabled.
  • locks.tf, diagnostics.tf: the SA's own lock + two blob diagnostic settings gated with && var.tfstate_enabled; refs indexed [0].
  • outputs.tf: tfstate_storage_account_nameone(azurerm_storage_account.tfstate[*].name) (null when disabled).
  • CHANGELOG.md: [3.5.0].

Backward compatibility

Default trueno change for existing consumers. random_string.storage_suffix lives in main.tf and is untouched, so Key Vault / Velero / cost-export / ACR names are unchanged when the toggle is off.

Validation

  • terraform fmt -check -recursive → exit 0
  • terraform init -backend=false → ok
  • terraform validate → Success! The configuration is valid.

Gates the module-managed Terraform state backend (resource group, storage
account, container, deployer role assignment, and the optional tfstate
private endpoint) behind var.tfstate_enabled (default true).

Default true preserves the existing self-bootstrap pattern, so current
consumers are unaffected. Set false when the backend lives in an external,
pre-provisioned storage account (e.g. a central bootstrap layer) — this
avoids an orphaned tfstate storage account per workload.

The shared random_string.storage_suffix (in main.tf) is untouched, so Key
Vault / Velero / cost-export / ACR names do not change when disabled.
Dependent satellites (resource lock, blob diagnostic settings, and the
tfstate_storage_account_name output) are gated/one()-guarded accordingly.
@danielgines
danielgines merged commit 137e70e into master Jun 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant