Prevent string conversion of dict containing string with var substitution
Fixes:
MODIFY
checkov/terraform/parser.py
checkov/terraform/parser.py
@@ -349,7 +349,7 @@ class Parser:
eval_map_by_var_name,
new_context, value, root_directory)
if replaced != var_base:
- if match.full_str == value:
+ if match.full_str == altered_value:
altered_value = replaced
else:
altered_value = altered_value.replace(match.full_str, str(replaced))

MODIFY
tests/terraform/parser/resources/parser_scenarios/merge_function/expected.json
tests/terraform/parser/resources/parser_scenarios/merge_function/expected.json
"Tag4": "four"
}
],
+ "local_local_manual": [
+ {
+ "Tag1": "one",
+ "Tag2": "two",
+ "Tag3": "three",
+ "Name": "Bob"
+ }
+ ],
"manual_to_local": [
{
"Tag4": "four",
"Tag2": "multiline_tag2",
"Tag4": "four"
}
+ ],
+ "static1": ["one"],
+ "static2": ["two"]
+ }
+ ],
+ "resource": [
+ {
+ "aws_something": {
+ "something": {
+ "tags": [
+ {
+ "Tag1": "one",
+ "Tag2": "two",
+ "Tag3": "three",
+ "Name": "Bob-one-two"
+ }
]
}
+ }
+ }
]
}
}
\ No newline at end of file

MODIFY
tests/terraform/parser/resources/parser_scenarios/merge_function/main.tf
tests/terraform/parser/resources/parser_scenarios/merge_function/main.tf
@@ -9,6 +9,7 @@ locals {
local_to_local = merge(local.common_tags, local.common_data_tags)
local_to_manual = merge(local.common_tags, {Tag4 = "four"})
+ local_local_manual = merge(local.common_tags, local.common_data_tags, {Name = "Bob"})
manual_to_local = merge({Tag4 = "four"}, local.common_tags)
manual_to_manual = merge({Tag4 = "four"}, {Tag5="five"})
@@ -36,4 +37,12 @@ locals {
{Tag4 = "four"},
{Tag2="multiline_tag2"}
)
+
+ static1 = "one"
+ static2 = "two"
+}
+
+resource "aws_something" "something" {
+ #
+ tags = merge(local.common_tags, local.common_data_tags, {Name = "Bob-${local.static1}-${local.static2}"})
}
\ No newline at end of file

Prevent string conversion of dict containing string with var substitution

Fixes: #873