Skip to content

Commit

Permalink
Merge pull request #393 from dinedal/fix_infinite_loop_on_variable_re…
Browse files Browse the repository at this point in the history
…solution

Fix infinite loop on variable resolution
  • Loading branch information
kanchwala-yusuf authored Nov 30, 2020
2 parents 4614d5d + d356d5c commit dbd5237
Showing 1 changed file with 8 additions and 0 deletions.
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 {
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

0 comments on commit dbd5237

Please sign in to comment.