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

Split variable evaluation / validation scope #2199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cam72cam
Copy link
Member

Currently, GraphNodeReferenceOutside is used to make sure that variables are evaluated in the correct scope. However, with the addition of function providers and "bugfixes" introduced in provider iteration, variables now require two completely distinct scopes.

One scope is used for variable evaluation from module call inputs, the other for the validation scope. These two scopes are now represented by the original struct in charge of the variable, and an new one which only contains the validation logic.

Only the new "validation scope" node provides the reference and will be depended on, other nodes may use the value post-validation.

Additionally ProviderFunctionTransformer now understands GraphNodeReferenceOutside, which fixes a few related bugs. Idealy, we could get rid of that interface, but due to how expansion is handled, it's quite tricky.

This also implements a lot of the required machinery for #1336.

Resolves #2175

Target Release

1.9.0

Checklist

  • I have read the contribution guide.
  • I have not used an AI coding assistant to create this PR.
  • I have written all code in this PR myself OR I have marked all code I have not written myself (including modified code, e.g. copied from other places and then modified) with a comment indicating where it came from.
  • I (and other contributors to this PR) have not looked at the Terraform source code while implementing this PR.

Go checklist

  • I have run golangci-lint on my change and receive no errors relevant to my code.
  • I have run existing tests to ensure my code doesn't break anything.
  • I have added tests for all relevant use cases of my code, and those tests are passing.
  • I have only exported functions, variables and structs that should be used from other packages.
  • I have added meaningful comments to all exported functions, variables, and structs.

Website/documentation checklist

  • I have locally started the website as described here and checked my changes.

@cam72cam cam72cam requested a review from a team as a code owner November 21, 2024 18:09
Copy link

Reminder for the PR assignee: If this is a user-visible change, please update the changelog as part of the PR.

Currently, GraphNodeReferenceOutside is used to make sure that variables
are evaluated in the correct scope.  However, with the addition of
function providers and "bugfixes" introduced in provider iteration,
variables now require two completely distinct scopes.

One scope is used for variable evaluation from module call inputs, the
other for the validation scope.  These two scopes are now represented
by the original struct in charge of the variable, and an new one which
only contains the validation logic.

Only the new "validation scope" node provides the reference and will be
depended on, other nodes may use the value post-validation.

Additionally ProviderFunctionTransformer now understands
GraphNodeReferenceOutside, which fixes a few related bugs.  Idealy, we
could get rid of that interface, but due to how expansion is handled,
it's quite tricky.

This also implements a lot of the required machinery for #1336.

Signed-off-by: Christian Mesh <[email protected]>
Copy link
Contributor

@Evi1Pumpkin Evi1Pumpkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Functions used in module calls values don't work as expected
3 participants