Omit empty tune block on remaining auth backends (#178)
ci/woodpecker/push/apply Pipeline was successful

terraform-provider-vault 5.6.0 panics in expandAuthMethodTune when an auth backend gets a tune block whose values are all null. #176 fixed the JWT backend; the approle, kubernetes, ldap and oidc backends still render tune unconditionally, so any mount of theirs without tune values crashes plan.

- Render tune via a dynamic block only when at least one tune value is set; values pass through unchanged
- Add tofu tests per module covering the unset and set cases
- Run the new module tests from make test and the tofu-module-tests hook

Reviewed-on: #178
Co-authored-by: unkin-agent <unkin-agent@unkin.net>
Co-committed-by: unkin-agent <unkin-agent@unkin.net>
This commit was merged in pull request #178.
This commit is contained in:
2026-11-14 19:02:09 +11:00
committed by BenVincent
parent 4ea4a881ae
commit 5245bcdc29
10 changed files with 148 additions and 19 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ repos:
always_run: true
- id: tofu-module-tests
name: tofu module tests pass
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'
entry: sh -c 'for m in auth_approle_backend auth_jwt_backend auth_jwt_role auth_kubernetes_backend auth_ldap_backend auth_oidc_backend; 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
+1 -1
View File
@@ -30,7 +30,7 @@ apply: init
test:
@uv run --with pyyaml --with pydantic python -m unittest discover -s tests -t .
@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
@for m in auth_approle_backend auth_jwt_backend auth_jwt_role auth_kubernetes_backend auth_ldap_backend auth_oidc_backend; 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..."
@@ -3,9 +3,13 @@ resource "vault_auth_backend" "approle" {
type = "approle"
path = var.path
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
}
}
}
@@ -0,0 +1,22 @@
mock_provider "vault" {}
variables {}
run "omit_tune_when_unset" {
command = plan
assert {
condition = length(vault_auth_backend.approle.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_auth_backend.approle.tune) == 1 && vault_auth_backend.approle.tune[0].max_lease_ttl == "1h"
error_message = "tune block must render with the configured values"
}
}
@@ -8,10 +8,14 @@ resource "vault_auth_backend" "kubernetes" {
type = "kubernetes"
path = var.path
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
}
}
}
@@ -0,0 +1,31 @@
mock_provider "vault" {
override_data {
target = data.vault_kv_secret_v2.auth_backend_config
values = { data = { kubernetes_ca_cert = "ca", token_reviewer_jwt = "jwt" } }
}
}
variables {
country = "au"
region = "syd1"
kubernetes_host = "https://kubernetes.default.svc"
}
run "omit_tune_when_unset" {
command = plan
assert {
condition = length(vault_auth_backend.kubernetes.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_auth_backend.kubernetes.tune) == 1 && vault_auth_backend.kubernetes.tune[0].max_lease_ttl == "1h"
error_message = "tune block must render with the configured values"
}
}
@@ -19,9 +19,13 @@ resource "vault_ldap_auth_backend" "ldap" {
alias_metadata = var.alias_metadata
username_as_alias = var.username_as_alias
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
}
}
}
}
@@ -0,0 +1,31 @@
mock_provider "vault" {
override_data {
target = data.vault_kv_secret_v2.auth_backend_config
values = { data = { url = "ldaps://ldap.example.net", binddn = "cn=bind", bindpass = "pass" } }
}
}
variables {
country = "au"
region = "syd1"
userdn = "ou=users,dc=example,dc=net"
}
run "omit_tune_when_unset" {
command = plan
assert {
condition = length(vault_ldap_auth_backend.ldap.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_ldap_auth_backend.ldap.tune) == 1 && vault_ldap_auth_backend.ldap.tune[0].max_lease_ttl == "1h"
error_message = "tune block must render with the configured values"
}
}
@@ -14,9 +14,13 @@ resource "vault_jwt_auth_backend" "oidc" {
oidc_client_secret = data.vault_kv_secret_v2.oidc_client.data["client_secret"]
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
}
}
}
@@ -0,0 +1,29 @@
mock_provider "vault" {
override_data {
target = data.vault_kv_secret_v2.oidc_client
values = { data = { client_id = "id", client_secret = "secret" } }
}
}
variables {
oidc_discovery_url = "https://identity.example.net/application/o/vault/"
}
run "omit_tune_when_unset" {
command = plan
assert {
condition = length(vault_jwt_auth_backend.oidc.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.oidc.tune) == 1 && vault_jwt_auth_backend.oidc.tune[0].max_lease_ttl == "1h"
error_message = "tune block must render with the configured values"
}
}