Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: interpolate the count config during the apply walk #17133

Merged
merged 2 commits into from
Jan 19, 2018

Conversation

apparentlymart
Copy link
Contributor

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 when count > 1 -- to ensure that it's available by the time we interpolate any remaining expressions in the config and any expressions within connection and provisioner blocks.

This error was masked by us sharing a single RawConfig instance between the plan and apply walks when terraform 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.

Previously we would return the raw error from strconv.ParseInt, which
includes details in its text that expose implementation details and are
thus not helpful to the user.

Instead, we use a locally-defined error message that talks only about
what the caller is expected to know: that count should be parsable as
an integer.
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 when count > 1 -- to ensure that it's available by the
time we interpolate any remaining expressions in the config and any
expressions within "connection" and "provisioner" blocks.

This error was masked by us sharing a single RawConfig instance between
the plan and apply walks when "terraform 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.
@apparentlymart apparentlymart merged commit b511caf into master Jan 19, 2018
@apparentlymart apparentlymart deleted the b-provisioner-interp-count branch February 5, 2018 19:15
@ghost
Copy link

ghost commented Apr 5, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ParseInt error on apply for count value
2 participants