fix(provider-generator): satisfy module provider configuration aliases on get - #383
fix(provider-generator): satisfy module provider configuration aliases on get#383jsteinich wants to merge 2 commits into
Conversation
…s on get `cdktn get` fetches a module schema by writing a synthetic root config that calls the module and running `terraform get` in it. A module declaring `configuration_aliases` in its `required_providers` makes that root config invalid - Terraform demands the caller pass those configurations in - and `terraform get` used to downgrade the resulting error to a warning and write the module manifest anyway, which is what the fetch relied on. Terraform 1.15 routed init and get through the graph-based install workflow (hashicorp/terraform#38217), which never reaches that downgrade and returns before writing the manifest. From 1.15.7 on, `cdktn get` therefore fails with "Missing required provider configuration" for any such module. OpenTofu still has the downgrade in both of its install paths and is unaffected. Read what the module actually declares instead of guessing up front: the first `terraform get` is treated as a fetch whose diagnostics are deferred (Terraform installs the module either way, it just skips the manifest), then the module's own `required_providers` tell us which aliased configurations to declare in the root and pass to the module call, and a second `terraform get` produces the manifest. Modules without aliases are unaffected, and a fetch that fails for any other reason still reports its original error. Fixes open-constructs#379 Co-Authored-By: Claude Opus 5 <[email protected]>
|
There is still a
The matrix shows that I published the credential-free reproduction harness here: It pins Node, pnpm, Go, Terraform 1.14.3, and Terraform 1.15.8 with mise. Would you prefer to include |
so0k
left a comment
There was a problem hiding this comment.
If you believe the fix for json should be a separate PR - then let me know and I'm ok with that - but maybe we could fix both in the same PR (unless it blows up the linecount)
…ules hcl2json only wraps HCL expressions in an interpolation. A module written in JSON syntax declares `"configuration_aliases": ["null.extra"]` and the reference comes through as a plain string, so the alias collector matched nothing and `cdktn get` still failed on Terraform 1.15.8 for JSON modules. Unwrap the interpolation when there is one and match the reference either way. Covered by a local .tf.json fixture alongside the HCL one, plus unit cases for the plain form and for entries that are not provider references. Co-Authored-By: Claude Opus 5 <[email protected]>
Fixes #379
cdktn getfetches a module schema by writing a synthetic root config that calls the module and runningterraform getin it. A module declaringconfiguration_aliasesin itsrequired_providersmakes that root config invalid — Terraform demands the caller pass those configurations in — andterraform getused to downgrade the resulting error to a warning and write the module manifest anyway, which is what the fetch relied on.Terraform 1.15 routed init and get through the graph-based install workflow (hashicorp/terraform#38217), which never reaches that downgrade (
installErrsOnlyno longer has any effect forget) and returns before writing the manifest. From 1.15.7 on,cdktn gettherefore fails with "Missing required provider configuration" for any such module, and.terraform/modules/modules.jsonis never written, so the failure cannot simply be tolerated. OpenTofu still has the downgrade in both of its install paths and is unaffected.Approach
Read what the module actually declares rather than guessing up front or parsing the error text:
terraform getis treated as a fetch whose diagnostics are deferred. Terraform installs the module either way — it just skips the manifest.required_providersblock (parsed with thehcl2jsoncall the harvest step already makes) says which aliased configurations are required.terraform getproduces the manifest.Modules without
configuration_aliasesare unaffected, and a fetch that fails for any other reason still reports its original error.Alternatives considered and rejected: parsing alias names out of the error prose (English-prose-dependent); reading them from the Terraform Registry API before fetching (
provider_dependenciesdoes not exposeconfiguration_aliases, and it would not cover git or local sources);terraform init -from-module(skips validation entirely but takes no version argument, so registry modules cannot be pinned); version-gating on Terraform >= 1.15 (no benefit — the declaration-driven flow is version-agnostic and also silences the pre-1.15 warning).execgains alogStderrAsDebugoption so the deferred fetch does not print an[ERROR]block that a following success contradicts. When the fetch turns out not to be salvageable, the held-back diagnostics are re-logged at error level before rethrowing, so that output is unchanged.Testing
local-module-provider-aliasesfixture and snapshot test, a test that a genuinely unfetchable module still fails loudly, and unit tests for the new helpers.@cdktn/provider-schemasuite passes against both Terraform 1.14.3 (which only warned) and 1.15.8 (which errors); the same suite fails on 1.15.8 without this change.🤖 Generated with Claude Code