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

CFn: add schema validation for resource providers #10795

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

simonrw
Copy link
Contributor

@simonrw simonrw commented May 8, 2024

Motivation

We use the CloudFormation resource provider schema to generate our scaffolded resources, but we don't make any assertions that what is returned by a resource provider conforms to the schema. Now that we have migrated all resources to the new resource provider API we should be stricter about the responses coming back from the resource providers. This will help us ensure parity with AWS CFn.

Changes

  • Implement a schema validation method in the ResourceProviderExecutor
    • at the moment, this only validates that all required fields are present, but will provide a place to put further validations in the future
    • the PhysicalResourceId is validated implicitly with the call to extract_physical_resource_id_from_model_with_schema, which raises an exception (in resolve_json_pointer) if the value is not present

Testing

The green CI pipeline run shows that all community resource providers already conform to the schema (:tada:). To check that the validation works, pick a resource provider and comment out setting one of the required fields.

@simonrw simonrw added aws:cloudformation AWS CloudFormation semver: patch Non-breaking changes which can be included in patch releases labels May 8, 2024
@simonrw simonrw self-assigned this May 8, 2024
Copy link

github-actions bot commented May 8, 2024

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 38m 7s ⏱️ - 1m 19s
2 992 tests ±0  2 681 ✅ ±0  311 💤 ±0  0 ❌ ±0 
2 994 runs  ±0  2 681 ✅ ±0  313 💤 ±0  0 ❌ ±0 

Results for commit 557ec1b. ± Comparison against base commit b8290ff.

♻️ This comment has been updated with latest results.

@simonrw simonrw force-pushed the cfn/schema-validation branch 2 times, most recently from 26ad7e6 to 80b2c45 Compare May 11, 2024 20:11
@simonrw simonrw marked this pull request as ready for review May 13, 2024 08:24
Copy link
Member

@pinzon pinzon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Copy link
Contributor Author

@simonrw simonrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes from review pairing with @dominikschubert and @Morijarti :

  • validation of required fields should be done before resource provider execution as this represents input values supplied by the user
  • we could validate no extra properties are assigned by the resource provider on SUCCESS
  • notes for the future:
    • we could typecheck the fields, possibly depending on how we want to handle implicit typecasting

@simonrw simonrw marked this pull request as draft May 22, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:cloudformation AWS CloudFormation semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants