fix(terraform): defer dynamic block expansion when for_each contains unknown values#33
Closed
blinkagent[bot] wants to merge 1 commit intomainfrom
Closed
fix(terraform): defer dynamic block expansion when for_each contains unknown values#33blinkagent[bot] wants to merge 1 commit intomainfrom
blinkagent[bot] wants to merge 1 commit intomainfrom
Conversation
…unknown values
Change the guard check in expandDynamic() from IsKnown() to
IsWhollyKnown() so that dynamic blocks with partially-resolved
for_each values (containing cty.DynamicVal in nested elements)
are deferred instead of expanded with stale data.
Previously, a for_each value like:
[{name: DynamicVal, value: "vscode"}]
would pass the IsKnown() check (the top-level tuple is known)
and expand the dynamic block with unresolved values. The block
would then be marked as expanded and never re-expanded, even
after subsequent evaluation passes resolve the nested locals.
IsWhollyKnown() recursively checks all nested elements, catching
the DynamicVal inside the tuple. Returning nil instead of an error
defers expansion without marking it as expanded, allowing the next
evaluation iteration to expand correctly once all locals resolve.
Fixes coder/coder#20930
Member
|
Fixed #37 |
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.
Problem
Dynamic blocks with
for_eachreferencing nested local values fail to expand correctly. When a local value references another local (e.g.,local.idescontainslocal.vscode_name), thefor_eachvalue may be partially resolved on the first evaluation pass, containingcty.DynamicValfor the unresolved references.The existing
IsKnown()check only verifies the top-level value (a tuple/list), which appears "known" even when its nested elements containDynamicVal. The dynamic block then expands with stale data and gets marked as expanded, preventing re-expansion on subsequent iterations when the context is fully resolved.Reproduction
Fix
Change the guard check in
expandDynamic()fromIsKnown()toIsWhollyKnown(), and returnnil, nil(defer) instead of an error.IsWhollyKnown()recursively checks all nested elements, catchingDynamicValinside tuples/objectsnil, nildefers expansion without marking the block as expandedTesting
coder/previewthat the nested localfor_eachnow correctly resolvespkg/iac/terraform/...tests passcoder/previewnon-E2E tests passFixes coder/coder#20930