core: interpolate the count config during the apply walk #17133
Merged
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.
Previously we would interpolate the count config (
ResourceConfig.RawCount
) only while preparing to dynamic-expand aggregate resource nodes. This is problematic because we do not dynamic-expand any resource nodes during the apply walk, and so previously the count value was not available for interpolation during apply and would result in an error.Now we interpolate
RawCount
once for each resource we visit during the apply walk -- even though that redundantly interpolates the same config multiple times whencount
> 1 -- to ensure that it's available by the time we interpolate any remaining expressions in the config and any expressions withinconnection
andprovisioner
blocks.This error was masked by us sharing a single
RawConfig
instance between the plan and apply walks whenterraform apply
is run with no explicit plan file argument, but was exposed by the workflow where the plan is written first to disk since in that case the interpolation result from during the plan phase is not present in the deflated plan object. For this reason, the new context test serializes the plan into an in-memory buffer and reloads it in order to simulate the effect of the two-step workflow.This fixes #16840.