Skip to content

CFNv2: implement describe-stack-resource #12912

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 19 commits into from
Jul 29, 2025
Merged

Conversation

simonrw
Copy link
Contributor

@simonrw simonrw commented Jul 25, 2025

Motivation

The current V2 CloudFormation provider does not support the describe_stack_resource operation. In order to reach parity with the v1 provider it must do.

Changes

  • Provide typing for the NodeResource in various places
  • Rework the way the resolved resources are propagated to provide more type safety and structure
  • Add ChangeSetModelValidator for validations we know happen before create_change_set returns (i.e. during the modeling phase). This can be a place to hook other validations as well
  • Validate logical resource ids are valid
  • Update the StackNotFoundError to handle yet another case, this time through an explicit message override
  • Implement DescribeStackResource
  • Add tests for describing non-existent things
  • Add test validating that stack parameters are given
  • Implement list-stack-resources to unskip another test
  • Unskip 9 tests

@simonrw simonrw added the semver: patch Non-breaking changes which can be included in patch releases label Jul 25, 2025
Copy link

github-actions bot commented Jul 25, 2025

Test Results - Preflight, Unit

21 991 tests  ±0   20 257 ✅ ±0   7m 1s ⏱️ +34s
     1 suites ±0    1 734 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 5cb7f8d. ± Comparison against base commit fb42a08.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jul 25, 2025

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 12s ⏱️ +3s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 5cb7f8d. ± Comparison against base commit fb42a08.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jul 25, 2025

LocalStack Community integration with Pro

    2 files  ±  0      2 suites  ±0   1h 43m 18s ⏱️ - 5m 8s
4 482 tests  - 460  4 155 ✅  - 14  327 💤  - 446  0 ❌ ±0 
4 484 runs   - 460  4 155 ✅  - 14  329 💤  - 446  0 ❌ ±0 

Results for commit 5cb7f8d. ± Comparison against base commit fb42a08.

This pull request removes 460 tests.
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_autoexpand_capability_requirement
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_and_then_remove_non_supported_resource_change_set
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_and_then_remove_supported_resource_change_set
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_and_then_update_refreshes_template_metadata
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_change_set_create_existing
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_change_set_invalid_params
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_change_set_missing_stackname
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_change_set_update_nonexisting
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_change_set_update_without_parameters
tests.aws.services.cloudformation.v2.ported_from_v1.api.test_changesets ‑ test_create_change_set_with_ssm_parameter
…

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jul 25, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   2h 19m 51s ⏱️
4 841 tests 4 361 ✅ 480 💤 0 ❌
4 847 runs  4 361 ✅ 486 💤 0 ❌

Results for commit 5cb7f8d.

♻️ This comment has been updated with latest results.

Copy link

Test Results (MA/MR) - Preflight, Unit

21 983 tests   20 249 ✅  6m 24s ⏱️
     1 suites   1 734 💤
     1 files         0 ❌

Results for commit cea3566.

Copy link

Test Results (amd64, MA/MR) - Acceptance

7 tests   5 ✅  3m 8s ⏱️
1 suites  2 💤
1 files    0 ❌

Results for commit cea3566.

Copy link

Test Results (amd64, MA/MR) - Integration, Bootstrap

    5 files      5 suites   2h 21m 53s ⏱️
4 839 tests 4 359 ✅ 480 💤 0 ❌
4 845 runs  4 359 ✅ 486 💤 0 ❌

Results for commit cea3566.

@simonrw simonrw marked this pull request as ready for review July 28, 2025 04:27
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

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

Nice to see the tests being unskipped! The implementation, the snapshots, and the tiny pipeline change are looking good! 💯

@@ -339,7 +339,7 @@ jobs:
AWS_DEFAULT_REGION: "us-east-1"
JUNIT_REPORTS_FILE: "pytest-junit-community-${{ matrix.group }}.xml"
TEST_PATH: "../../localstack/tests/aws/" # TODO: run tests in tests/integration
PYTEST_ARGS: "${{ env.TINYBIRD_PYTEST_ARGS }}${{ env.TESTSELECTION_PYTEST_ARGS }}--splits ${{ strategy.job-total }} --group ${{ matrix.group }} --durations-path ../../localstack/.test_durations --store-durations"
PYTEST_ARGS: "${{ env.TINYBIRD_PYTEST_ARGS }}${{ env.TESTSELECTION_PYTEST_ARGS }}--splits ${{ strategy.job-total }} --group ${{ matrix.group }} --durations-path ../../localstack/.test_durations --store-durations --ignore ../../localstack/tests/aws/services/cloudformation/v2"
Copy link
Member

Choose a reason for hiding this comment

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

FYI: As far as I can tell, this change really just migrates the ignore introduced in #12871 to the tests executed against Pro.

Copy link
Member

@baermat baermat left a comment

Choose a reason for hiding this comment

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

SQS changes are looking good 👍

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.

Looks very good 👍 . The only blocker is the location of the new tests.

@@ -1061,3 +1060,13 @@ def test_stack_resource_not_found(deploy_cfn_template, aws_client, snapshot):

snapshot.add_transformer(snapshot.transform.regex(stack.stack_name, "<stack-name>"))
snapshot.match("Error", ex.value.response)


@markers.aws.validated
Copy link
Member

@pinzon pinzon Jul 28, 2025

Choose a reason for hiding this comment

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

comment: can't believe we didn't have this validation tested. 😅
Edit: This test should be moved too.

Copy link
Member

Choose a reason for hiding this comment

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

Changes: The tests look great but I'd prefer if we move them to the original CFn test folder and conditionally skip them if the old engine doesn't support them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At some point in the near future I want to re-merge the tests again so they we don't have divergence. And yes these are tests that don't work with the old engine so would require explicit skipping. Is it ok to move the tests at that point? I might work on this tomorrow if this PR is approved

Copy link
Member

Choose a reason for hiding this comment

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

comment: Nice 🎉

Comment on lines -426 to 443
self.resources[logical_resource_id].update(extra_resource_properties)
# XXX for legacy delete_stack compatibility
self.resources[logical_resource_id]["LogicalResourceId"] = logical_resource_id
self.resources[logical_resource_id]["Type"] = resource_type

status_from_action = EventOperationFromAction[action.value]
physical_resource_id = (
self._get_physical_id(logical_resource_id)
extra_resource_properties["PhysicalResourceId"]
if resource_provider
else MOCKED_REFERENCE
)
self.resources[logical_resource_id]["PhysicalResourceId"] = physical_resource_id
resolved_resource = ResolvedResource(
Properties=event.resource_model,
LogicalResourceId=logical_resource_id,
Type=resource_type,
LastUpdatedTimestamp=datetime.now(timezone.utc),
ResourceStatus=ResourceStatus(f"{status_from_action}_COMPLETE"),
PhysicalResourceId=physical_resource_id,
)
# TODO: do we actually need this line?
resolved_resource.update(extra_resource_properties)

self.resources[logical_resource_id] = resolved_resource

Copy link
Member

@pinzon pinzon Jul 28, 2025

Choose a reason for hiding this comment

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

question/comment: Does this mean that we only store the resource description when the event is successful? Is that correct? If not, we could move the storage one level above,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You make an excellent point. However we don't have much test coverage of this situation. It should be fairly easy to trigger: set up a resource definition with deliberately invalid data. Then the stack will be left in a bad state, HOWEVER we don't yet model that state and behaviour. I think that's a pre-requisite. I would feel nervous to implement something as fundamental as that without test coverage. I would love it if at the end of this initiative we have correct rollback behaviour but I'm not sure we will yet.

Perhaps I can work on this in a follow up?

@pinzon pinzon self-requested a review July 28, 2025 21:22
@alexrashed alexrashed added this to the 4.8 milestone Jul 29, 2025
@simonrw simonrw mentioned this pull request Jul 29, 2025
@coveralls
Copy link

Coverage Status

coverage: 85.982% (+34.6%) from 51.377%
when pulling 5cb7f8d on cfn/v2/describe-stack-resources
into fb42a08 on main.

@simonrw simonrw merged commit 5535768 into main Jul 29, 2025
40 checks passed
@simonrw simonrw deleted the cfn/v2/describe-stack-resources branch July 29, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants