-
Notifications
You must be signed in to change notification settings - Fork 170
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
Conversation
There was a problem hiding this 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
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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@xescugc it's done :) |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RS
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
7c9fe4d
to
74a0fc0
Compare
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