Skip to content

Commit

Permalink
code nits: removed multiple type computations
Browse files Browse the repository at this point in the history
  • Loading branch information
Rchanger committed Jun 30, 2021
1 parent 896408e commit 5d8ed50
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pkg/iac-providers/terraform/commons/local-references.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ func (r *RefResolver) ResolveLocalRef(localRef, callerRef string) interface{} {
return localRef
}

valKind := reflect.TypeOf(val).Kind()

// replace the local value reference string with actual value
if reflect.TypeOf(val).Kind() == reflect.String || reflect.TypeOf(val).Kind() == reflect.Map {
if valKind == reflect.String || valKind == reflect.Map {
valStr := ""

if reflect.TypeOf(val).Kind() == reflect.Map {
if valKind == reflect.Map {
data, err := json.Marshal(val)
if err != nil {
zap.S().Errorf("failed to convert expression '%v', ref: '%v'", localAttr.Expr, localRef)
Expand Down
5 changes: 3 additions & 2 deletions pkg/iac-providers/terraform/commons/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ func (r *RefResolver) ResolveRefs(config jsonObj) jsonObj {
if valueStr, ok := value.(string); ok {
var temp jsonObj
err := json.Unmarshal([]byte(valueStr), &temp)
if err == nil {
if err != nil {
zap.S().Debugf("failed to unmarshal json string %s", valueStr)
} else {
value = temp
}
zap.S().Debugf("resolved value is not a json object", err)
}

config[k] = value
Expand Down
6 changes: 4 additions & 2 deletions pkg/iac-providers/terraform/commons/variable-references.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ func (r *RefResolver) ResolveVarRef(varRef, callerRef string) interface{} {
}
zap.S().Debugf("resolved variable ref '%v', value: '%v'", varRef, val)

if reflect.TypeOf(val).Kind() == reflect.String || reflect.TypeOf(val).Kind() == reflect.Map {
valKind := reflect.TypeOf(val).Kind()

if valKind == reflect.String || valKind == reflect.Map {
valStr := ""

if reflect.TypeOf(val).Kind() == reflect.Map {
if valKind == reflect.Map {
data, err := json.Marshal(val)
if err != nil {
zap.S().Errorf("failed to convert expression '%v', ref: '%v'", hclVar, varRef)
Expand Down

0 comments on commit 5d8ed50

Please sign in to comment.