Skip to content

Fix for _replace_dynamic_values in canary file auto-generator #1103

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/rpdk/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,12 @@ def _replace_dynamic_values(self, properties: Dict[str, Any]) -> Dict[str, Any]:
if isinstance(value, dict):
properties[key] = self._replace_dynamic_values(value)
elif isinstance(value, list):
properties[key] = [self._replace_dynamic_value(item) for item in value]
properties[key] = [
self._replace_dynamic_values(item)
if isinstance(item, dict)
else self._replace_dynamic_value(item)
for item in value
]
else:
return_value = self._replace_dynamic_value(value)
properties[key] = return_value
Expand All @@ -1468,7 +1473,12 @@ def _replace_dynamic_values_with_root_key(
if isinstance(value, dict):
properties[root_key] = self._replace_dynamic_values(value)
elif isinstance(value, list):
properties[root_key] = [self._replace_dynamic_value(item) for item in value]
properties[root_key] = [
self._replace_dynamic_values(item)
if isinstance(item, dict)
else self._replace_dynamic_value(item)
for item in value
]
else:
return_value = self._replace_dynamic_value(value)
properties[root_key] = return_value
Expand Down
11 changes: 11 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2915,6 +2915,7 @@ def test_create_template_file(mock_yaml_dump, project):
"Property5": "{{uuid}}",
"Property6": "{{account}}",
"Property7": "prefix-{{uuid}}-sufix",
"Property8": [{"Nested": "{{test123}}"}],
}
}
setup_contract_test_data(project.root, contract_test_data)
Expand Down Expand Up @@ -2955,6 +2956,7 @@ def test_create_template_file(mock_yaml_dump, project):
"Property5": ANY,
"Property6": {"Fn::Sub": "${AWS::AccountId}"},
"Property7": ANY,
"Property8": [{"Nested": {"Fn::ImportValue": "test123"}}],
},
}
},
Expand Down Expand Up @@ -3196,6 +3198,7 @@ def test_generate_canary_files_with_patch_inputs(mock_yaml_dump, project):
def test_create_template_file_with_patch_inputs(mock_yaml_dump, project):
update_value_1 = "Value1b"
update_value_2 = "Value2b"
updated_value_3 = "{{test456}}"

contract_test_data = {
"CreateInputs": {
Expand All @@ -3206,6 +3209,7 @@ def test_create_template_file_with_patch_inputs(mock_yaml_dump, project):
"Property5": "{{uuid}}",
"Property6": "{{account}}",
"Property7": "prefix-{{uuid}}-sufix",
"Property8": [{"Nested": "{{test123}}"}],
},
"PatchInputs": [
{
Expand All @@ -3228,6 +3232,11 @@ def test_create_template_file_with_patch_inputs(mock_yaml_dump, project):
"path": "/Property4",
"value": ["{{region}}", update_value_2],
},
{
"op": "replace",
"path": "/Property8",
"value": [{"Nested": updated_value_3}],
},
],
}
setup_contract_test_data(project.root, contract_test_data)
Expand Down Expand Up @@ -3269,6 +3278,7 @@ def test_create_template_file_with_patch_inputs(mock_yaml_dump, project):
"Property5": ANY,
"Property6": {"Fn::Sub": "${AWS::AccountId}"},
"Property7": ANY,
"Property8": [{"Nested": {"Fn::ImportValue": "test456"}}],
},
}
},
Expand All @@ -3295,6 +3305,7 @@ def test_create_template_file_with_patch_inputs(mock_yaml_dump, project):
"Property5": ANY,
"Property6": {"Fn::Sub": "${AWS::AccountId}"},
"Property7": ANY,
"Property8": [{"Nested": {"Fn::ImportValue": "test123"}}],
},
}
},
Expand Down