Skip to content

fix cfn template join with noValue #12163

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

Merged
merged 1 commit into from
Jan 23, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ def _resolve_refs_recursively(
raise Exception(
f"Cannot resolve CF Fn::Join {value} due to null values: {join_values}"
)
return value[keys_list[0]][0].join([str(v) for v in join_values])
return value[keys_list[0]][0].join(
[str(v) for v in join_values if v != "__aws_no_value__"]
)

if stripped_fn_lower == "sub":
item_to_sub = value[keys_list[0]]
Expand Down
10 changes: 10 additions & 0 deletions tests/aws/services/cloudformation/test_template_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ def test_sub_number_type(self, deploy_cfn_template):
assert stack.outputs["Threshold"] == threshold
assert stack.outputs["Period"] == period

@markers.aws.validated
def test_join_no_value_construct(self, deploy_cfn_template, snapshot, aws_client):
stack = deploy_cfn_template(
template_path=os.path.join(
os.path.dirname(__file__), "../../templates/engine/join_no_value.yml"
)
)

snapshot.match("join-output", stack.outputs)


class TestImports:
@markers.aws.validated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,5 +673,15 @@
}
}
}
},
"tests/aws/services/cloudformation/test_template_engine.py::TestIntrinsicFunctions::test_join_no_value_construct": {
"recorded-date": "22-01-2025, 14:01:46",
"recorded-content": {
"join-output": {
"JoinConditionalNoValue": "",
"JoinOnlyNoValue": "",
"JoinWithNoValue": "Sample"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"tests/aws/services/cloudformation/test_template_engine.py::TestIntrinsicFunctions::test_get_azs_function[us-west-2]": {
"last_validated_date": "2024-05-09T08:33:45+00:00"
},
"tests/aws/services/cloudformation/test_template_engine.py::TestIntrinsicFunctions::test_join_no_value_construct": {
"last_validated_date": "2025-01-22T14:01:46+00:00"
},
"tests/aws/services/cloudformation/test_template_engine.py::TestIntrinsicFunctions::test_sub_number_type": {
"last_validated_date": "2024-08-09T06:55:16+00:00"
},
Expand Down
34 changes: 34 additions & 0 deletions tests/aws/templates/engine/join_no_value.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Conditions:
active: !Equals [ true, true ]
inactive: !Equals [ true, false ]

Resources:
Parameter:
Type: AWS::SSM::Parameter
Properties:
Type: String
Value: Sample
Name: commands

Outputs:
JoinWithNoValue:
Value:
Fn::Join:
- ","
- - !GetAtt Parameter.Value
- !Ref AWS::NoValue

JoinOnlyNoValue:
Value:
Fn::Join:
- ","
- - !Ref AWS::NoValue

JoinConditionalNoValue:
Value:
Fn::Join:
- ","
- - Fn::If:
- active
- !Ref AWS::NoValue
- !Ref AWS::NoValue
Loading