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

hcl: avoid mutual interpolation #125

Merged
merged 3 commits into from
Jul 2, 2020
Merged

hcl: avoid mutual interpolation #125

merged 3 commits into from
Jul 2, 2020

Conversation

tormath1
Copy link
Contributor

this kind of interpolation (between 2 resources) leads to cyclic references at TF runtime. To avoid it, we build a list of current relations between resources then we check if a relation is already present before adding a ref to another resource

@tormath1 tormath1 added Type: Enhancement Provide a new feature or improve an existing one Status: Need review labels Jun 29, 2020
@tormath1 tormath1 self-assigned this Jun 29, 2020
@tormath1 tormath1 changed the title hcl: fix mutual interpolation hcl: avoid mutual interpolation Jun 29, 2020
Copy link
Member

@xescugc xescugc left a comment

Choose a reason for hiding this comment

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

Chagelog is missing too

hcl/writer.go Outdated
Comment on lines 218 to 227
func isMutualInterpolation(target, source string, relations *[][]string) bool {
for _, r := range *relations {
if (r[0] == target &&
r[1] == source) ||
(r[1] == target &&
r[0] == source) {
return true
}
}
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to have a map[string]struct{} where the key is source+target, so we can easily check without iterating over all the array.

Also document what is what.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's documented 🤔

// isMutualInterpolation will simply go through the list of relations to find out
// if a relation is already present between the two resources

@tormath1
Copy link
Contributor Author

tormath1 commented Jul 2, 2020

@xescugc it's done :)

Comment on lines +219 to +224
func isMutualInterpolation(target, source string, relations *map[string]struct{}) bool {
if _, ok := (*relations)[fmt.Sprintf("%s+%s", source, target)]; ok {
return true
}
if _, ok := (*relations)[fmt.Sprintf("%s+%s", target, source)]; ok {
return true
Copy link
Member

Choose a reason for hiding this comment

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

We actually do not need the + on the interpolation, it's more up to you if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean ? the + is just a way to create the key in the relations map 🤔

Copy link
Member

@xescugc xescugc left a comment

Choose a reason for hiding this comment

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

RS

tormath1 added 3 commits July 2, 2020 16:06
this kind of interpolation (between 2 resources) leads to cyclic
references at TF runtime.
To avoid it, we build a list of current relations between resources
then we check if a relation is already present before adding a ref
to another resource
@tormath1 tormath1 force-pushed the mt-fix-interpolation branch from 7c9fe4d to 74a0fc0 Compare July 2, 2020 14:07
@tormath1 tormath1 merged commit b05705b into master Jul 2, 2020
@tormath1 tormath1 deleted the mt-fix-interpolation branch July 2, 2020 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Provide a new feature or improve an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants