fix(cert_manager,external_dns): move cross-variable validations to terraform_data preconditions#315
Merged
Merged
Conversation
…rraform_data preconditions Terraform/OpenTofu variable validation blocks can only reference the variable being validated itself. Cross-variable conditions (e.g. checking cloud_provider inside another variable's validation) cause a plan-time error. Fixes the same pattern in two modules: - cert_manager: removed all cross-variable validation blocks and introduced a new validation.tf with a terraform_data precondition resource. Updated tests to use expect_failures = [terraform_data.provider_validation]. - external_dns: updated validation.tf preconditions from != null to length() > 0 (variables defaults changed from null to ""), fixed oci_compartment_ocid default from " " (space) to "", and uncommented 5 previously disabled tests in external_dns_cross_provider.tftest.hcl that were blocked by the null eager-evaluation bug in locals.tf. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
gdrojas
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Terraform/OpenTofu
validationblocks inside avariablecan only reference the variable being validated itself (var.<name>). Cross-variable conditions — such as checkingvar.cloud_providerinside the validation ofvar.gcp_sa_email— cause the following plan-time error:This PR fixes the issue in both affected modules by migrating cross-variable validations to
lifecycle.preconditionblocks on aterraform_dataresource (the same pattern introduced inexternal_dnsvia #310).cert_managervalidationblocks fromvariables.tf(10 blocks across GCP, AWS, Azure, Cloudflare, and OCI variables).validation.tfwith aterraform_data "provider_validation"resource containing the equivalentpreconditionchecks.expect_failures = [terraform_data.provider_validation]instead of the previousexpect_failures = [var.X].external_dnsnullto""(cloudflare_token,aws_region,aws_iam_role_arn,azure_client_id,azure_subscription_id,azure_resource_group,azure_tenant_id). Thenulldefaults caused eager evaluation failures inlocals.tfwhen any provider config was instantiated with null values.oci_compartment_ocidhaddefault = " "(a space), which silently bypassed the!= ""precondition check. Changed todefault = "".validation.tfpreconditions from!= nulltolength(...) > 0. Thecloudflare_tokenprecondition uses!= null && length(...) > 0to handle tests that explicitly passnull.external_dns_cross_provider.tftest.hcl(rejects_invalid_policy,rejects_invalid_type,private_type_in_release_name,base_config_consistency,all_providers_in_config_map) that were blocked by the null eager-evaluation bug.Test plan
tofu testpasses forinfrastructure/commons/cert_manager— 19 passed, 0 failedtofu testpasses forinfrastructure/commons/external_dns— 37 passed, 0 failedtofu fmt,tofu validate,tofu test)🤖 Generated with Claude Code