X Tutup
Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

fix(cloudformation): skip properties of conditional resources with false conditions#13664

Merged
pinzon merged 4 commits intolocalstack:mainfrom
sodre:fix/cfn-v2-conditional-resource-deletion-13609
Feb 5, 2026
Merged

fix(cloudformation): skip properties of conditional resources with false conditions#13664
pinzon merged 4 commits intolocalstack:mainfrom
sodre:fix/cfn-v2-conditional-resource-deletion-13609

Conversation

@sodre
Copy link
Contributor

@sodre sodre commented Jan 30, 2026

Summary

  • Fix CloudFormation v2 engine failing to delete stacks with conditional resources
  • Skip property evaluation for resources whose condition is false
  • Add regression tests for both Fn::If wrapped GetAtt and direct conditional resource references

Root Cause

In visit_node_resource, properties were visited unconditionally before checking if the resource's condition was true. This caused !GetAtt references inside conditional resources to be evaluated even when the resource was never created (condition=false), resulting in "Unresolved resource dependencies" errors during stack deletion.

The Fix

Check whether a resource's condition evaluates to true before visiting its properties. This prevents resolution of references to other conditional resources that may not exist.

Test plan

  • Added test_delete_stack_with_conditional_getatt - tests !GetAtt wrapped in Fn::If
  • Added test_delete_stack_with_conditional_resource_referencing_conditional - tests !GetAtt inside a conditional resource
  • All 19 condition tests pass (7 skipped AWS-only)

Fixes #13609

🤖 Generated with Claude Code

…lse conditions

When deleting a CloudFormation stack, the v2 engine was incorrectly
evaluating properties of conditional resources even when their condition
evaluated to false (meaning the resource was never created). This caused
deletion to fail with "Unresolved resource dependencies" errors when a
conditional resource referenced another conditional resource via GetAtt.

The fix checks whether a resource's condition is true BEFORE visiting
its properties, preventing resolution of references to resources that
may not exist.

Fixes localstack#13609

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

@localstack-bot localstack-bot left a comment

Choose a reason for hiding this comment

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

Welcome to LocalStack! Thanks for raising your first Pull Request and landing in your contributions. Our team will reach out with any reviews or feedbacks that we have shortly. We recommend joining our Slack Community and share your PR on the #community channel to share your contributions with us. Please make sure you are following our contributing guidelines and our Code of Conduct.

@localstack-bot
Copy link
Contributor

localstack-bot commented Jan 30, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@sodre
Copy link
Contributor Author

sodre commented Jan 30, 2026

I have read the CLA Document and I hereby sign the CLA

@sodre
Copy link
Contributor Author

sodre commented Jan 30, 2026

recheck

localstack-bot added a commit that referenced this pull request Jan 30, 2026
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.

Hi @sodre thank you for your interest in contributing to LocalStack and kudos for using AI to help you code. There are some issues with this PR:

  1. test_delete_stack_with_conditional_getatt passes without your fixes. So either the test is unable to reproduce the issue or the issue has been already fixed.

  2. test_delete_stack_with_conditional_resource_referencing_conditional without your changes to change_set_model_preproc.py, the template is rejected even before deploying. It seems that our validation incorrectly rejects this template because is unable to handle the conditional definition correctly. Your changes fixes that. You could repurpose your test for that behavior.

  3. When submitting a PR, you need to make sure to test against AWS using TEST_TARGET=AWS_CLOUD; AWS_DEFAULT_PROFILE=ls-sandbox; AWS_DEFAULT_REGION=us-east-1. This generates a validation file that tells the reviewer that your tests are AWS valid.

@sodre
Copy link
Contributor Author

sodre commented Feb 4, 2026

@pinzon, thank you for the feedback. I would not have been able to write the tests without the AI help in this case, given that localstack is a black box for me.

I (and Claude) will work on making a smaller change set than the one proposed here.

I will update the PR to address item 3 as well.

…idation

- Remove test_delete_stack_with_conditional_getatt (passed without fix)
- Rename and repurpose test to verify template acceptance with conditions
- Use snapshot matching instead of manual assertions
- Delete unused conditional-getatt-delete.yaml template
- Add AWS-validated snapshot and validation data

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sodre sodre force-pushed the fix/cfn-v2-conditional-resource-deletion-13609 branch from eae4b84 to 317f124 Compare February 4, 2026 02:21
@sodre sodre requested a review from pinzon February 4, 2026 02:22
@alexrashed alexrashed added semver: patch Non-breaking changes which can be included in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Feb 4, 2026
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.

Thanks for the changes. Let's just remove the extra comments. In the meantime I'll approve the CI checks. 👍

sodre and others added 2 commits February 4, 2026 09:54
…ete.yaml

Co-authored-by: Cristopher Pinzón <18080804+pinzon@users.noreply.github.com>
Co-authored-by: Cristopher Pinzón <18080804+pinzon@users.noreply.github.com>
@sodre sodre requested a review from pinzon February 4, 2026 14:55
@sodre
Copy link
Contributor Author

sodre commented Feb 4, 2026

Thanks for the changes. Let's just remove the extra comments. In the meantime I'll approve the CI checks. 👍

Awesome! I've committed your changes.

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.

Great PR. Thank you for addressing the comments 👍

@sodre
Copy link
Contributor Author

sodre commented Feb 4, 2026

Thank you @pinzon, I credit Claude, my co-author :)

@pinzon pinzon merged commit cf9a6fc into localstack:main Feb 5, 2026
37 checks passed
@sodre sodre deleted the fix/cfn-v2-conditional-resource-deletion-13609 branch February 6, 2026 05:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes 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.

bug: CloudFormation v2 engine fails to delete stack with conditional resource references

4 participants

X Tutup