Skip to content

Commit

Permalink
fix(terraform): prevent side effects when updating variable rendering (
Browse files Browse the repository at this point in the history
…#6087)

* fix(terraform): prevent side effects when updating variable rendering

* keep the structure

---------

Co-authored-by: Steve Vaknin <[email protected]>
  • Loading branch information
SteveVaknin and SteveVaknin authored Mar 14, 2024
1 parent 3c855bd commit db8fb18
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions checkov/terraform/graph_builder/local_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,16 @@ def update_list_attribute(

if len(key_parts) == 1:
idx = force_int(key_parts[0])
inner_config = config[0]
# Avoid changing the config and cause side effects
inner_config = pickle_deepcopy(config[0])

if idx is not None and isinstance(inner_config, list):
if not inner_config:
# happens when config = [[]]
return config

inner_config[idx] = new_value
return config
return [inner_config]
entry_to_update = int(key_parts[0]) if key_parts[0].isnumeric() else -1
for i, config_value in enumerate(config):
if entry_to_update == -1:
Expand Down

0 comments on commit db8fb18

Please sign in to comment.