-
Notifications
You must be signed in to change notification settings - Fork 507
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
fixes: recursive loop when parent and child module has same local block #900
Conversation
Codecov Report
@@ Coverage Diff @@
## master #900 +/- ##
==========================================
+ Coverage 78.41% 78.42% +0.01%
==========================================
Files 168 168
Lines 4470 4501 +31
==========================================
+ Hits 3505 3530 +25
- Misses 741 747 +6
Partials 224 224
|
@@ -86,8 +87,20 @@ func (r *RefResolver) ResolveLocalRef(localRef, callerRef string) interface{} { | |||
} | |||
|
|||
// replace the local value reference string with actual value | |||
if reflect.TypeOf(val).Kind() == reflect.String { | |||
valStr := val.(string) | |||
if reflect.TypeOf(val).Kind() == reflect.String || reflect.TypeOf(val).Kind() == reflect.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.
Instead of invoking reflect.TypeOf(val).Kind()
3 times, you can store invoke once and store the value in a local variable. reflect function calls are generally heavy and slow from what I've read and experienced.
if err == nil { | ||
value = temp | ||
} | ||
zap.S().Debugf("resolved value is not a json object", err) |
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.
The message should be more generic here like ("failed to unmarshal json string %s", valueStr). because in some cases the problem can be with the temp struct too.
@@ -87,8 +88,20 @@ 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 { | |||
valStr := val.(string) | |||
if reflect.TypeOf(val).Kind() == reflect.String || reflect.TypeOf(val).Kind() == reflect.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.
same. use a variable to store reflect values
"type": "aws_iam_user", | ||
"config": { | ||
"name": "joe != \"\" ? \"joe-fred\" : fred", | ||
"tags": "${merge(${merge({\n CreatedBy = \"Terraform\"\n }, {\"this\":\"that\"})},\n {\n Name = joe != \"\" ? \"joe-fred\" : fred\n })}" |
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.
can you change it to how you changed this part https://github.com/accurics/terrascan/pull/900/files#diff-9e7e2f86151ba69659926d94f991b79ee8c8e03d62733d1aa2dd72207485282aR406 ?
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.
That is not possible because here it is a string with an expression that needs to be evaluated. Once we add support for functions this will also change.
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
fixes #851