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: correctly skip conditionally disabled resources #13238
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
|
Member
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. Nit: Consider adding a validation test about a situation where an output references a conditionally skip resource.
Contributor
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. Good idea, thanks! I'll tackle this in a follow up |
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,7 @@ | ||
| import os.path | ||
|
|
||
| import pytest | ||
| from localstack_snapshot.snapshots.transformer import SortingTransformer | ||
| from tests.aws.services.cloudformation.conftest import skip_if_legacy_engine | ||
|
|
||
| from localstack.services.cloudformation.v2.utils import is_v2_engine | ||
|
|
@@ -153,7 +154,7 @@ def test_dependent_get_att(self, aws_client, snapshot): | |
| snapshot.match("dependent_ref_exc", e.value.response) | ||
|
|
||
| @markers.aws.validated | ||
| @pytest.mark.skipif(condition=not is_aws_cloud(), reason="not supported yet") | ||
| @skip_if_legacy_engine() | ||
|
Member
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. 🥳 |
||
| def test_dependent_ref_intrinsic_fn_condition(self, aws_client, deploy_cfn_template): | ||
| """ | ||
| Checks behavior of un-refable resources | ||
|
|
@@ -515,3 +516,37 @@ def test_update_conditions(self, deploy_cfn_template, aws_client): | |
| assert aws_client.s3.head_bucket(Bucket=bucket_1) | ||
| with pytest.raises(aws_client.s3.exceptions.ClientError): | ||
| aws_client.s3.head_bucket(Bucket=bucket_2) | ||
|
|
||
| @markers.aws.validated | ||
| @pytest.mark.parametrize("should_deploy", ["yes", "no"]) | ||
| @skip_if_legacy_engine() | ||
| def test_references_to_disabled_resources( | ||
| self, deploy_cfn_template, aws_client, should_deploy, snapshot | ||
| ): | ||
| snapshot.add_transformer( | ||
| SortingTransformer("StackResources", lambda e: e["LogicalResourceId"]) | ||
| ) | ||
| snapshot.add_transformer(SortingTransformer("Parameters", lambda e: e["ParameterKey"])) | ||
| snapshot.add_transformer(snapshot.transform.key_value("PhysicalResourceId")) | ||
| snapshot.add_transformer(snapshot.transform.cloudformation_api()) | ||
|
|
||
| parameter_value = short_uid() | ||
| snapshot.add_transformer(snapshot.transform.regex(parameter_value, "<parameter-value>")) | ||
|
|
||
| stack = deploy_cfn_template( | ||
| template_path=os.path.join( | ||
| os.path.dirname(__file__), "../../../templates/references_to_conditions.yml" | ||
| ), | ||
| parameters={ | ||
| "Toggle": should_deploy, | ||
| "ParameterValue": parameter_value, | ||
| }, | ||
| ) | ||
|
|
||
| describe_stack_res = aws_client.cloudformation.describe_stacks(StackName=stack.stack_id) | ||
| snapshot.match("stack-description", describe_stack_res) | ||
|
|
||
| describe_resources = aws_client.cloudformation.describe_stack_resources( | ||
| StackName=stack.stack_id | ||
| ) | ||
| snapshot.match("resources-description", describe_resources) | ||
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| Parameters: | ||
| Toggle: | ||
| Type: String | ||
|
|
||
| ParameterValue: | ||
| Type: String | ||
|
|
||
| Conditions: | ||
| ShouldDeploy: | ||
| Fn::Equals: | ||
| - !Ref Toggle | ||
| - "yes" | ||
|
|
||
| Resources: | ||
| BaseParameter: | ||
| # We need a single resource to deploy | ||
| Type: AWS::SSM::Parameter | ||
| Properties: | ||
| Type: String | ||
| Value: !Ref ParameterValue | ||
|
|
||
| ConditionalParameter: | ||
| Type: AWS::SSM::Parameter | ||
| Condition: ShouldDeploy | ||
| Properties: | ||
| Type: String | ||
| Value: !Ref ParameterValue | ||
|
|
||
| AnotherResource: | ||
| Type: AWS::SSM::Parameter | ||
| Condition: ShouldDeploy | ||
| Properties: | ||
| Type: String | ||
| Value: !GetAtt ConditionalParameter.Value | ||
|
|
||
| Outputs: | ||
| ConditionalParameterValue: | ||
| Condition: ShouldDeploy | ||
| Value: !GetAtt ConditionalParameter.Value |
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.
Praise: Glad the new engine is easily modifiable.