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 infinite loop on variable resolution #393

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/iac-providers/terraform/v12/variable-references.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func (r *RefResolver) ResolveVarRef(varRef string) interface{} {
if reflect.TypeOf(val).Kind() == reflect.String {
valStr := val.(string)
resolvedVal := strings.Replace(varRef, varExpr, valStr, 1)
if varRef == resolvedVal {
Copy link
Contributor

Choose a reason for hiding this comment

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

@dinedal we do not require the change here

Copy link
Contributor

Choose a reason for hiding this comment

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

Come to think of it, this may not hurt us at all.

zap.S().Debugf("resolved str variable ref refers to self: '%v'", varRef)
return varRef
}
zap.S().Debugf("resolved str variable ref: '%v', value: '%v'", varRef, resolvedVal)
return r.ResolveStrRef(resolvedVal)
}
Expand Down Expand Up @@ -148,6 +152,10 @@ func (r *RefResolver) ResolveVarRefFromParentModuleCall(varRef string) interface
if reflect.TypeOf(val).Kind() == reflect.String {
valStr := val.(string)
resolvedVal := strings.Replace(varRef, varExpr, valStr, 1)
if varRef == resolvedVal {
zap.S().Debugf("resolved str variable ref refers to self: '%v'", varRef)
return varRef
}
zap.S().Debugf("resolved str variable ref: '%v', value: '%v'", varRef, string(resolvedVal))
return r.ResolveStrRef(resolvedVal)
}
Expand Down