Skip to content
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

(assertions): match properties against *all* resources of a given type #21269

Closed
1 of 2 tasks
joel-aws opened this issue Jul 21, 2022 · 2 comments · Fixed by #22007
Closed
1 of 2 tasks

(assertions): match properties against *all* resources of a given type #21269

joel-aws opened this issue Jul 21, 2022 · 2 comments · Fixed by #22007
Labels
@aws-cdk/assertions Related to the @aws-cdk/assertv2 package effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@joel-aws
Copy link
Contributor

joel-aws commented Jul 21, 2022

Describe the feature

Given a Stack with resources of the same type (e.g., AWS::S3::Bucket), easily apply assertions against all of those resources.

Currently, has_resource_properties() (and similar methods) returns True if a single resource matches, even if other resources don't match.

Use Case

Given a stack with two S3 Buckets:

s3.Bucket(self, "aes", encryption=s3.BucketEncryption.S3_MANAGED)
s3.Bucket(self, "no-aes", encryption=s3.BucketEncryption.UNENCRYPTED)

When a has_resource_properties assertion is run against AWS::S3::Bucket resources:

template.has_resource_properties(
    type="AWS::S3::Bucket",
    props={
        "BucketEncryption": {
            "ServerSideEncryptionConfiguration": [
                {"ServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}
            ]
        }
    },
)

Then the test will fail, as only one of the Buckets has SSE enabled. As is implemented now, the test passes.

Proposed Solution

  • Add a boolean property, like: has_resource_properties(match_all_resources=True), such that all resources of a given type must match the props, else it will return False.
  • Implement a new method like has_resources_properties() that applies to all resources of a given type.

Also:

  • Make it very obvious in the documentation that has_resource_properties (and similar methods) will return True if a single match is found.

Other Information

cc: @mrgrain

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.33.0

Environment details (OS name and version, etc.)

MacOS 11.6.7

@joel-aws joel-aws added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 21, 2022
@github-actions github-actions bot added the @aws-cdk/assertions Related to the @aws-cdk/assertv2 package label Jul 21, 2022
@peterwoodworth peterwoodworth added p1 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 28, 2022
@kaizencc kaizencc added p2 effort/small Small work item – less than a day of effort and removed p1 effort/medium Medium work item – several days of effort labels Jul 29, 2022
@kaizencc kaizencc removed their assignment Jul 29, 2022
@kaizencc
Copy link
Contributor

Match.allResources() is something we could implement.

@mergify mergify bot closed this as completed in #22007 Nov 2, 2022
mergify bot pushed a commit that referenced this issue Nov 2, 2022
…2007)

Closes #21269

----

### All Submissions:

* [X ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Nov 2, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assertions Related to the @aws-cdk/assertv2 package effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants