Skip to content

aws: conditions can be referenced (Condition key, Fn::If) but never declared; a build that names one succeeds and CloudFormation rejects the template #2068

Closed

Description

@lex00

What

The aws lexicon can reference a CloudFormation condition but cannot declare one. A source that uses the resource-level Condition attribute or Fn::If builds with no diagnostic to a template CloudFormation rejects, because nothing can write the Conditions section the reference needs.

The import side of the same gap, where chant import drops a template's Conditions section silently, is #2069.

CloudFormation's Conditions section is where a condition is defined; a resource's Condition key, an output's Condition key, and Fn::If reference a condition by logical name and are invalid unless that name is declared there (Conditions syntax). chant has the references and not the declaration:

surface status where
resource-level Condition: "<name>" passes through to the template lexicons/aws/src/serializer.ts:400 (if (attrs.Condition) resource.Condition = ...), tested at serializer.test.ts:721 and integration.test.ts:129
output-level Condition typed on CFOutput serializer.ts:87
Fn::If emitted intrinsics.ts:100-122 (If(conditionName, a, b))
Conditions section not in the template type, never emitted serializer.ts:38-46 (CFTemplate has Parameters, Resources, Outputs, Transform, Metadata, Description)
Fn::Equals / Fn::And / Fn::Or / Fn::Not no authoring intrinsic intrinsics.ts exports Sub, Ref, GetAtt, If, Join, Select, Split, Base64, GetAZs
a Condition declarable (the way Parameter in parameter.ts is lifted into Parameters at serializer.ts:332) does not exist

Repro (chant 0.56.0, bfe0c42)

import { LogGroup, Parameter, If } from "@intentius/chant-lexicon-aws";
export const cutover = new Parameter("String", { defaultValue: "false" });
export const gated = new (LogGroup as any)(
  { LogGroupName: If("DoCutover", "/gated/on", "/gated/off"), RetentionInDays: 7 },
  { Condition: "DoCutover" },
);

chant build src --lexicon aws -o template.json succeeds with no diagnostic. The template has keys AWSTemplateFormatVersion, Parameters, Resources; the resource carries "Condition": "DoCutover" and the Fn::If. There is nothing to write DoCutover with.

$ cfn-lint template.json
E8002 Resource 'gated' references undefined condition 'DoCutover'
E8002 Resource 'gated' references undefined condition 'DoCutover' in Fn::If
E1028 Fn::If references undefined condition 'DoCutover' in resource 'gated'
E3015 Resource 'gated' references undefined condition 'DoCutover'

(as any because the generated class's second constructor argument is attributes?: Record<string, unknown> in packages/core/src/runtime.ts:25; the typed surface does not name Condition either.)

Why it matters

Conditions are the standard CloudFormation idiom for "this resource exists only when a parameter says so" (an environment tier, a feature flag, a cutover switch). Today the only way to express that in chant is a separate stack per switch. Found while designing an ECS-to-EKS cutover that wanted one listener rule gated on a cutover parameter.

Do

  1. A Condition declarable in the aws lexicon, lifted into a Conditions section by the serializer the way Parameter is lifted into Parameters, with authoring intrinsics Equals, And, Or, Not and a Condition reference (the { "Condition": "<name>" } form allowed inside other conditions).
  2. Type the resource-level Condition attribute on the generated class signature (today it needs as any), and accept a Condition declarable there as well as a string.
  3. A post-synth check that fails the build when a template references a condition it does not declare, which is what cfn-lint E8002 does and what would have caught this.
  4. Then aws import: the Conditions section, Condition keys and conditioned Outputs are dropped silently; Fn::If survives dangling #2069 for the import side.

Accept

  • The repro builds to a template cfn-lint accepts, with Conditions.DoCutover present.
  • Referencing an undeclared condition is a build error, not a silent success.

Activity

  1. changed the title [-]aws: conditions can be referenced but never declared; import drops the Conditions section silently[/-] [+]aws: conditions can be referenced (Condition key, Fn::If) but never declared; a build that names one succeeds and CloudFormation rejects the template[/+] on Sep 3, 2026
  2. added a commit that references this issue on Sep 3, 2026
    8cf7746
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions