Skip to content

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
aws-cloudformation:mainfrom
Varshith-Kali:fix/5074-5075-dead-condition-validation
Open

Varshith-Kali wants to merge 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:fix/5074-5075-dead-condition-validation

Conversation

@Varshith-Kali

Copy link
Copy Markdown
Contributor

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:

  1. The context solver gave every Fn::Equals a free Symbol, even when both sides are literals and the result is constant. Pinning such a condition to its impossible value stayed satisfiable.
  2. _add_value_constraints built its value domain from AllowedValues union every compared value, so a comparison against a disallowed value could still be true in the solver.
  3. Properties.validate and outputs Value.validate caught Unsatisfiable when pinning a resource or output Condition to True and then validated unpinned (the fix(rules): don't crash when a resource or output condition can never be true #4786 fallback for the E3001/E6001: unhandled Unsatisfiable when a resource or output Condition can never be true #4785 crash). The Fn::If rule likewise kept descending into a branch after its pin failed.

Fix

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

Caveats

Signed-off-by: Varshith Puli pulivarshit@gmail.com

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant