Repository navigation
fix(conditions): do not validate resources, outputs, or Fn::If branches that can never be reached - #5077
Open
Varshith-Kali wants to merge 1 commit into
Conversation
…es that can never be reached Fixes aws-cloudformation#5074 and aws-cloudformation#5075. A resource whose Condition can never be true was still validated: pinning the condition to True raised Unsatisfiable, which Properties.validate caught and then validated the resource unpinned (the fallback from aws-cloudformation#4786). CloudFormation ignores entities associated with a false condition and never evaluates their properties, so the dead resource is now skipped instead. W8003 still reports the condition, and the aws-cloudformation#4785 crash stays fixed because the exception is still caught. The same skip applies to outputs in Value.py. For the solver to know a condition can never be true, two gaps are closed. A static Fn::Equals now folds to BooleanTrue/BooleanFalse in the context solver (with CloudFormation string comparison semantics, so [true, "true"] is true), mirroring the older solver. And in _add_value_constraints, when a parameter has AllowedValues the domain is those values only, so Fn::Equals against a value outside the list is always false instead of satisfiable. Fn::If branches that are provably unreachable are reported as W1028 and no longer descended into, matching the resource behaviour. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #5074
Fixes #5075
Problem
(#5074) A resource whose Condition is a constant-false Fn::Equals of literals was validated anyway: E1161/E3031 on a bucket that is never created, E1019/E3024 on an out-of-range Fn::Select inside a dead resource, E3060 overlap between a dead subnet and a live one. All three templates deploy CREATE_COMPLETE.
(#5075) A condition comparing a String parameter against a value outside its AllowedValues was treated as possibly true, so E1151 fired on the dead Fn::If branch (template A) and the dead conditional resource (template B). Controls C and D, where the compared value is allowed, correctly keep their E1151.
Root cause
Three gaps in the condition engine and its callers:
Unsatisfiablewhen a resource or outputConditioncan never be true #4785 crash). The Fn::If rule likewise kept descending into a branch after its pin failed.Fix
Unsatisfiablewhen a resource or outputConditioncan never be true #4785 crash does not return; W8003 still reports the condition. This changes the fix(rules): don't crash when a resource or output condition can never be true #4786 test expectations: a property error on a resource that can never be created is no longer reported, matching the deploy evidence in Resource with a constant-false Condition is still validated (E1161/E3031, E1019/E3024, E3060) #5074.Note on overlap: the static fold and the Fn::If branch skip are the same hunks as in #5026 (which fixes #5023). Whichever PR merges second will need a small rebase; the hunks are identical, so the rebase is mechanical. #5075 template E now matches the with-#5026 output shown in the issue (W1028 only).
Tests
Unsatisfiablewhen a resource or outputConditioncan never be true #4785 template C reports E3002 on the ungated control only, with no exception.Caveats
Signed-off-by: Varshith Puli pulivarshit@gmail.com