Repository navigation
Description
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
- A
Conditiondeclarable in the aws lexicon, lifted into aConditionssection by the serializer the wayParameteris lifted intoParameters, with authoring intrinsicsEquals,And,Or,Notand aConditionreference (the{ "Condition": "<name>" }form allowed inside other conditions). - Type the resource-level
Conditionattribute on the generated class signature (today it needsas any), and accept aConditiondeclarable there as well as a string. - 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.
- 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.DoCutoverpresent. - Referencing an undeclared condition is a build error, not a silent success.
Activity
[-]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[/+]feat(aws): CloudFormation conditions can be declared, checked, and im…
docs(lexicons): keep the twin regeneration to the pages this PR edits
docs(lexicons): the fountain, k8s, cedar, github, gitlab, terraform, …