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

fix(misconf): properly expand dynamic blocks #7612

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nikpivkin
Copy link
Contributor

@nikpivkin nikpivkin commented Sep 28, 2024

Description

This PR separates the logic for expanding dynamic blocks from expanding the for-each meta argument.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@nikpivkin nikpivkin marked this pull request as ready for review October 7, 2024 03:15
@nikpivkin nikpivkin requested a review from simar7 as a code owner October 7, 2024 03:16
@@ -567,7 +567,7 @@ resource "something" "else" {
for_each = toset(["true"])

content {
ok = each.value
ok = blah.value
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reviewers: this test should not have run successfully because dynamic blocks do not create an each object.

expected: []any{"ssh", "http", "https"},
},
{
name: "map key",
Copy link
Member

Choose a reason for hiding this comment

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

can we rename the case accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 1a3282c

}
}
}`,
},
Copy link
Member

Choose a reason for hiding this comment

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

maybe add an explicit expected block with the nil value or a comment to explain it so we don't think it's been missed by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 1a3282c


realBlockType := b.TypeLabel()
if realBlockType == "" {
return nil, errors.New("dynamic block must have 1 label")
Copy link
Member

Choose a reason for hiding this comment

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

we seem to have been using fmt.Errorf elsewhere, should we stick to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fmt.Errorf is used to format the string

return expanded, errors.Join(errs...)
}

func (b *Block) validateForEach() (cty.Value, error) {
Copy link
Member

@simar7 simar7 Oct 17, 2024

Choose a reason for hiding this comment

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

Can we add test cases for the error paths in this func?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test covers those cases

Signed-off-by: nikpivkin <[email protected]>
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.

fix(terraform): handle for-each arguments properly fix(terraform): expand dynamic blocks from top to bottom
2 participants