This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
CFN: add more validations to intrinsic FnEquals #13217
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d07b2fe
Fn::Split args validation
pinzon b5f6aea
cfn: add more validations to intrinsic functions
pinzon 6d764d0
CFN: Add Validation to FnEquals
pinzon b0f5338
skip if v1
pinzon 840ba70
remove unrelated validation
pinzon 38c6319
remove unrelated snapshot and validation
pinzon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import json | ||
| import os.path | ||
|
|
||
| import pytest | ||
| from botocore.exceptions import ClientError | ||
| from localstack_snapshot.snapshots.transformer import SortingTransformer | ||
| from tests.aws.services.cloudformation.conftest import skip_if_legacy_engine | ||
|
|
||
|
|
@@ -550,3 +552,29 @@ def test_references_to_disabled_resources( | |
| StackName=stack.stack_id | ||
| ) | ||
| snapshot.match("resources-description", describe_resources) | ||
|
|
||
|
|
||
| class TestValidateConditions: | ||
| @markers.aws.validated | ||
| @skip_if_legacy_engine | ||
| def test_validate_equals_args_len(self, aws_client, snapshot): | ||
| template = { | ||
| "Conditions": {"ShouldDeploy": {"Fn::Equals": ["a"]}}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL you can have a condition that's unused! |
||
| "Resources": { | ||
| "Topic1": { | ||
| "Type": "AWS::SNS::Topic", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| stack_name = f"stack-{short_uid()}" | ||
| change_set_name = f"ch-{short_uid()}" | ||
| with pytest.raises(ClientError) as ex: | ||
| aws_client.cloudformation.create_change_set( | ||
| StackName=stack_name, | ||
| ChangeSetName=change_set_name, | ||
| ChangeSetType="CREATE", | ||
| TemplateBody=json.dumps(template), | ||
| ) | ||
|
|
||
| snapshot.match("error", ex.value.response) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2451,5 +2451,21 @@ | |
| "Tags": [] | ||
| } | ||
| } | ||
| }, | ||
| "tests/aws/services/cloudformation/test_change_set_fn_split.py::TestValidations::test_validate_args_len": { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: where did these snapshots come from? I guess they are left over from your split PR (#13244), can we remove them before merging?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. Nice catch 👍 |
||
| "recorded-date": "02-10-2025, 20:16:50", | ||
| "recorded-content": { | ||
| "error": { | ||
| "Error": { | ||
| "Code": "ValidationError", | ||
| "Message": "Template error: every Fn::Split object requires two parameters, (1) a string delimiter and (2) a string to be split or a function that returns a string to be split.", | ||
| "Type": "Sender" | ||
| }, | ||
| "ResponseMetadata": { | ||
| "HTTPHeaders": {}, | ||
| "HTTPStatusCode": 400 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I guess this is only needed because in your test you have an unused condition, but in general this should not be required since resources would refer to the conditions which would cause the visiting process to visit the conditions, right?
I'm glad we have this extra parity with explicitly visiting the conditions (perhaps we should explicitly visit all nodes?) but it seems like a more contrived change than it needs to be.
Uh oh!
There was an error while loading. Please reload this page.
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.
I'll leave this here for now. But I have an idea to discuss later.