From a7dc1e9d255e10f99e747db295c0fec7ebfe9732 Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Tue, 10 Nov 2026 23:32:19 +1100 Subject: [PATCH] Omit empty tune block on JWT auth backends and import the orphaned mount --- .pre-commit-config.yaml | 2 +- Makefile | 2 +- .../modules/auth_jwt_backend/main.tf | 12 ++++++--- .../auth_jwt_backend/tests/tune.tftest.hcl | 26 +++++++++++++++++++ modules/vault_cluster/state_migrations.tf | 6 +++++ 5 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 modules/vault_cluster/modules/auth_jwt_backend/tests/tune.tftest.hcl diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e52510e..8257fed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: always_run: true - id: tofu-module-tests name: tofu module tests pass - entry: sh -c 'cd modules/vault_cluster/modules/auth_jwt_role && tofu init -backend=false -input=false >/dev/null && tofu test' + entry: sh -c 'for m in auth_jwt_backend auth_jwt_role; do (cd modules/vault_cluster/modules/$m && tofu init -backend=false -input=false >/dev/null && tofu test) || exit 1; done' language: system pass_filenames: false always_run: true diff --git a/Makefile b/Makefile index 6d03509..171d3f6 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ apply: init test: @uv run --with pyyaml --with pydantic python -m unittest discover -s tests -t . - @cd modules/vault_cluster/modules/auth_jwt_role && tofu init -backend=false -input=false >/dev/null && tofu test + @for m in auth_jwt_backend auth_jwt_role; do (cd modules/vault_cluster/modules/$$m && tofu init -backend=false -input=false >/dev/null && tofu test) || exit 1; done format: @echo "Formatting OpenTofu files..." diff --git a/modules/vault_cluster/modules/auth_jwt_backend/main.tf b/modules/vault_cluster/modules/auth_jwt_backend/main.tf index cc874f9..93911f2 100644 --- a/modules/vault_cluster/modules/auth_jwt_backend/main.tf +++ b/modules/vault_cluster/modules/auth_jwt_backend/main.tf @@ -6,9 +6,13 @@ resource "vault_jwt_auth_backend" "jwt" { bound_issuer = var.bound_issuer default_role = var.default_role - tune { - default_lease_ttl = var.default_lease_ttl - max_lease_ttl = var.max_lease_ttl - listing_visibility = var.listing_visibility + # provider 5.6.0 panics on an all-null tune block + dynamic "tune" { + for_each = anytrue([for v in [var.default_lease_ttl, var.max_lease_ttl, var.listing_visibility] : v != null]) ? [1] : [] + content { + default_lease_ttl = var.default_lease_ttl + max_lease_ttl = var.max_lease_ttl + listing_visibility = var.listing_visibility + } } } diff --git a/modules/vault_cluster/modules/auth_jwt_backend/tests/tune.tftest.hcl b/modules/vault_cluster/modules/auth_jwt_backend/tests/tune.tftest.hcl new file mode 100644 index 0000000..6279b21 --- /dev/null +++ b/modules/vault_cluster/modules/auth_jwt_backend/tests/tune.tftest.hcl @@ -0,0 +1,26 @@ +mock_provider "vault" {} + +variables { + path = "jwt/github/iuclabs" + oidc_discovery_url = "https://token.actions.githubusercontent.com" + bound_issuer = "https://token.actions.githubusercontent.com" +} + +run "omit_tune_when_unset" { + command = plan + + assert { + condition = length(vault_jwt_auth_backend.jwt.tune) == 0 + error_message = "no tune block may render when every tune value is null" + } +} + +run "render_tune_when_set" { + command = plan + variables { max_lease_ttl = "1h" } + + assert { + condition = length(vault_jwt_auth_backend.jwt.tune) == 1 && vault_jwt_auth_backend.jwt.tune[0].max_lease_ttl == "1h" + error_message = "tune block must render with the configured values" + } +} diff --git a/modules/vault_cluster/state_migrations.tf b/modules/vault_cluster/state_migrations.tf index e9a2020..1d9014e 100644 --- a/modules/vault_cluster/state_migrations.tf +++ b/modules/vault_cluster/state_migrations.tf @@ -425,3 +425,9 @@ moved { from = vault_policy.policies["pki_root/pki_root_roles_admin"] to = module.vault_policy["pki_root/roles/admin"].vault_policy.this } + +# Mount enabled by a create that crashed before state was written +import { + to = module.auth_jwt_backend["jwt/github/iuclabs"].vault_jwt_auth_backend.jwt + id = "jwt/github/iuclabs" +}