Compare commits

..

2 Commits

Author SHA1 Message Date
399cf38fb4 style: tofu fmt the two files my multi-env change reformatted
All checks were successful
Helm Charts / Detect changed charts (pull_request) Successful in 39s
Helm Charts / Detect changed charts (push) Successful in 42s
Helm Charts / Library charts tool (push) Has been skipped
Helm Charts / Library charts tool (pull_request) Has been skipped
Helm Charts / Application charts pgcat (push) Has been skipped
Helm Charts / Application charts pgcat (pull_request) Has been skipped
Whitespace-only. `tofu fmt` realigned two spots that my Phase A edits
shifted:
- app_roles/main.tf: the REASSIGN revocation-statement trailing comment
  re-aligned after the GRANT line gained ${local.owner_role}
- variables.tf: the applications object keys re-aligned after adding the
  longer `envs` key

The two pre-existing unformatted files (factory_auth.tf, terraform.tfvars)
are left as-is — they were already unformatted on origin/main and are
outside this PR's scope.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-15 14:15:02 +02:00
5de9793bdf modules: add env/envs parameter to app_roles + app_policy (multi-env)
All checks were successful
Helm Charts / Detect changed charts (push) Successful in 1m18s
Helm Charts / Detect changed charts (pull_request) Successful in 38s
Helm Charts / Library charts tool (push) Has been skipped
Helm Charts / Library charts tool (pull_request) Has been skipped
Helm Charts / Application charts pgcat (push) Has been skipped
Helm Charts / Application charts pgcat (pull_request) Has been skipped
Phase A of the multi-environment evolution agreed in the erp repo design
thread. Both modules gain an optional env coordinate that defaults to
"prod"; by the elision rule, env=prod produces the existing single-env
derived names character-for-character, so every existing app's tofu plan
should be a no-op.

app_roles (per-instance module — caller iterates over envs):
- variables.tf: add optional env = "prod"
- main.tf: compute local.instance via elision rule + local.owner_role
  (snake-case <name>_<env>_role for the Postgres owner)
- main.tf: substitute local.name -> local.instance in all derived names
  (dynamic role name, k8s role name, SA bindings, token_policies)
- outputs.tf: add env + instance outputs; kvv2_path_prefix now derives
  from local.instance (== local.name when env=prod -> backwards-compat)

app_policy (per-repo module — accepts list of envs):
- variables.tf: add optional envs = ["prod"]
- main.tf: compute local.instances + local.non_prod_instances
- main.tf: refactor kvv2 ops rules to dynamic blocks iterating local.instances
  preserving the original rule order (data, delete, undelete, destroy,
  metadata) so prod-only apps render a byte-identical policy document
- main.tf: allowed_parameter blocks for k8s role's bound_service_account_*
  and token_policies use comprehensions over local.instances
- main.tf: keep vault_policy.app (the env=prod runtime policy) at its
  original address; add vault_policy.app_non_prod via for_each over
  non_prod_instances for the other envs

Top-level wiring:
- iac/variables.tf: add envs = optional(list(string), ["prod"]) to the
  applications set(object) type
- iac/main.tf: pass envs = each.value.envs through to app_policies

`tofu validate` passes. Every existing app's tofu plan should report no
changes because: (1) env="prod" defaults are used everywhere, (2) the
elision rule makes local.instance == local.name for prod, (3) dynamic
rule blocks preserve declaration order, (4) the new app_non_prod resource
is created via for_each over an empty set when no non-prod envs are
declared.

Phase B (factory postgres iac + argocd + runbook docs) and Phase D
(erp iac/main.tf for_each + activate sandbox) follow in their own PRs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-15 13:35:04 +02:00
2 changed files with 12 additions and 8 deletions

View File

@@ -8,14 +8,18 @@
locals { locals {
name = lower(var.name) name = lower(var.name)
envs = [for e in var.envs : lower(e)] envs = [for e in var.envs : lower(e)]
# Elision rule: env=prod → bare name; else <name>-<env> # Elision rule: env=prod → bare name; else <name>-<env>
instances = [for e in local.envs : e == "prod" ? local.name : "${local.name}-${e}"] instances = [for e in local.envs : e == "prod" ? local.name : "${local.name}-${e}"]
# Non-prod instances only (for the per-env runtime policy iteration that doesn't touch the prod state address)
non_prod_instances = [for e in local.envs : "${local.name}-${e}" if e != "prod"] non_prod_instances = [for e in local.envs : "${local.name}-${e}" if e != "prod"]
# Per-instance SA name/namespace sets used by the CI policy's allowed_parameter blocks. # Per-instance SA name/namespace sets used by the CI policy's allowed_parameter blocks.
per_instance_sa_names = { for inst in local.instances : inst => concat([inst], var.service_account_names) } per_instance_sa_names = { for inst in local.instances : inst => concat([inst], var.service_account_names) }
per_instance_sa_namespaces = { for inst in local.instances : inst => concat([inst], var.service_account_namespaces) } per_instance_sa_namespaces = { for inst in local.instances : inst => concat([inst], var.service_account_namespaces) }
# Backwards-compat aliases kept for any caller that referenced these (unused outside the module).
bound_service_account_names = concat([var.name], var.service_account_names)
bound_service_account_namespaces = concat([var.name], var.service_account_namespaces)
} }
data "vault_policy_document" "ops" { data "vault_policy_document" "ops" {

View File

@@ -5,15 +5,15 @@ data "vault_auth_backend" "kubernetes" {
locals { locals {
name = lower(var.name) name = lower(var.name)
env = lower(var.env) env = lower(var.env)
database = var.database == null ? local.instance : var.database
# Elision rule (factory runbook conventions.md): # Elision rule (factory runbook conventions.md):
# env == prod → identical to the single-env baseline (no suffix) # env == prod → identical to the single-env baseline (no suffix)
# else → kebab-case "<name>-<env>" for K8s/Vault paths. # else → kebab-case "<name>-<env>" for K8s/Vault paths
# Postgres owner role stays snake-case for consistency with the existing "_role" suffix.
instance = local.env == "prod" ? local.name : "${local.name}-${local.env}" instance = local.env == "prod" ? local.name : "${local.name}-${local.env}"
# Postgres owner role stays snake-case for consistency with the existing "_role" suffix.
owner_role = local.env == "prod" ? "${local.name}_role" : "${local.name}_${local.env}_role" owner_role = local.env == "prod" ? "${local.name}_role" : "${local.name}_${local.env}_role"
database = var.database == null ? local.instance : var.database
bound_service_account_names = concat([local.instance], var.service_account_names) bound_service_account_names = concat([local.instance], var.service_account_names)
bound_service_account_namespaces = concat([local.instance], var.service_account_namespaces) bound_service_account_namespaces = concat([local.instance], var.service_account_namespaces)