refactor(cloudformation): read property types from the vendored resource schemas (#5988)

* refactor(cloudformation): read property types from the vendored resource schemas

Follow-up asked on #5958: the types EventsCfnProvisioner checked a rule
target's members against were written by hand from describe-type, and
LambdaCfnProvisioner named the JSON type of each property it reads. They
now come from src/main/resources/aws/cfn-property-types.json, which
tools/aws/regen_cfn_property_types.py generates from the resource
schemas AWS publishes for us-east-1, in the request shapes' layout so
RequestShapeModel reads it: a structure, list, map or scalar per shape,
and "json" for what a schema leaves free.

The schemas come from AWS's live archive rather than a pinned package.
cfn-lint ships copies, but widens some types: a Lambda environment
variable's value takes any JSON type there and a string in the published
schema, where CloudFormation refuses an object or a list with "Property
[AB] expected type: String, found: JSONObject" (measured). The archive
keeps no older copy, so the generator follows the IAM data's split:
--check is offline and structural and runs on every pull request,
--verify compares a fresh generation with the vendored file and runs in
cfn-schema-drift.yml, weekly and on changes to the file or its generator.

CfnPropertyTypes.Reader walks the vendored shapes instead of type trees,
maps included: a map's values are read as its value shape, and a
mismatch names the key, as CloudFormation does ("Property [h] expected
type: String, found: JSONObject", measured). Every member of a rule
target is now read against its schema type, not only the four #5958
typed, and Lambda reads the properties it already typed through the same
reader, nested members included (VpcConfig.SubnetIds, EphemeralStorage.
Size, ImageConfig.Command, TracingConfig.Mode, Environment.Variables).
The messages for the newly checked members were measured on
CloudFormation (eu-west-1) and are in the tests.

* fix(cloudformation): keep a literal list's blank entries where the template put them

Review of #5988: the reader read every list of strings through the
engine's resolveStringList, which drops blank entries, so a rule
target's HttpParameters.PathParameterValues ["", "b"] became ["b"]
and moved "b" into the first wildcard. CloudFormation passes a literal
list on as written (measured: SecurityGroups ["", "sg-..."] reaches the
target as both). A literal list is now read through the engine's new
resolveLiteralList, which keeps blanks and still expands a list-valued
intrinsic in place; a list an intrinsic yields keeps the engine's
reading. Lambda's literal lists, read through the same reader, keep their
blanks too, for Lambda to judge as on AWS.

resolveLiteralList delegates to the private resolveListElements rather
than opening it: tests that mock the engine and call resolveStringList's
real code would otherwise get the mock's empty list from it, as
IamUserCfnProvisionerTest did.

* refactor(cloudformation): read a launch configuration's MetadataOptions by its schema shape

Review of #5988: #5964, merged after this branch opened, read
AWS::AutoScaling::LaunchConfiguration's MetadataOptions through the type
trees this PR removes. The generator now vendors that resource type too,
and AutoScalingGroupCfnProvisioner reads the block by the shape its
published schema declares (HttpTokens and HttpEndpoint strings,
HttpPutResponseHopLimit an integer, the same types #5964 wrote by hand),
so its tests pass unchanged. The hop limit's type is an anchor of the
generator's offline check.
This commit is contained in:
Alessandro Lattao authored and GitHub committed 2026-10-19 12:40:17 -04:00
1 parent 83147f204e
commit e5a206554f
16 files changed
+1406 -170

No files matched your search

@@ -36,6 +36,7 @@ class CloudFormationEventsRuleTargetTest {
private static final String STRING_SUBNETS_STACK = TestFixtures.uniqueName("compat-cfn-rule-subnets");
private static final String FLOAT_STACK = TestFixtures.uniqueName("compat-cfn-rule-float");
private static final String BOOLEAN_STACK = TestFixtures.uniqueName("compat-cfn-rule-boolean");
private static final String INPUT_STACK = TestFixtures.uniqueName("compat-cfn-rule-input");
private static final String CLUSTER =
"{\"Fn::Sub\": \"arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:cluster/compat-absent\"}";
private static final String ROLE =
@@ -56,7 +57,7 @@ class CloudFormationEventsRuleTargetTest {
static void cleanup() {
if (cfn != null) {
// DeleteStack answers for a stack that is gone too, so a failure here is a real one.
for (String stack : List.of(KEPT_STACK, STRING_SUBNETS_STACK, FLOAT_STACK, BOOLEAN_STACK)) {
for (String stack : List.of(KEPT_STACK, STRING_SUBNETS_STACK, FLOAT_STACK, BOOLEAN_STACK, INPUT_STACK)) {
cfn.deleteStack(request -> request.stackName(stack));
}
cfn.close();
@@ -153,6 +154,20 @@ class CloudFormationEventsRuleTargetTest {
+ " expected type: Boolean, found: String)"));
}
/** Measured on AWS (eu-west-1, 2026-10-19): every target member is typed, Input among them. */
@Test
@DisplayName("an Input that is an object fails template validation")
void anInputThatIsAnObjectFailsTheStack() throws InterruptedException {
cfn.createStack(request -> request.stackName(INPUT_STACK).templateBody("""
{"Resources": {"Rule": {"Type": "AWS::Events::Rule", "Properties": {
"EventPattern": {"source": ["compat.rule.targets"]},
"Targets": [{"Id": "T", "Arn": %s, "RoleArn": %s, "Input": {"a": 1}}]}}}}
""".formatted(CLUSTER, ROLE)));
assertThat(TestFixtures.awaitStackTerminal(cfn, INPUT_STACK, DEPLOY_TIMEOUT)).isEqualTo("ROLLBACK_COMPLETE");
assertThat(reasons(INPUT_STACK)).anyMatch(reason ->
reason.contains("Property [Input] expected type: String, found: JSONObject"));
}
private static String ecsRule(String parameters, String ecsMembers) {
return """
{"Parameters": %s,
@@ -33,6 +33,7 @@ class CloudFormationLambdaObjectPropertyTest {
private static final String LAYERS_STACK = TestFixtures.uniqueName("compat-cfn-layers-object");
private static final String DELIMITED_STACK = TestFixtures.uniqueName("compat-cfn-comma-delimited");
private static final String STRING_PARAMETER_STACK = TestFixtures.uniqueName("compat-cfn-string-parameter");
private static final String NESTED_STACK = TestFixtures.uniqueName("compat-cfn-nested-member");
private static CloudFormationClient cfn;
@@ -50,6 +51,7 @@ class CloudFormationLambdaObjectPropertyTest {
cfn.deleteStack(request -> request.stackName(LAYERS_STACK));
cfn.deleteStack(request -> request.stackName(DELIMITED_STACK));
cfn.deleteStack(request -> request.stackName(STRING_PARAMETER_STACK));
cfn.deleteStack(request -> request.stackName(NESTED_STACK));
cfn.close();
}
}
@@ -144,6 +146,17 @@ class CloudFormationLambdaObjectPropertyTest {
reason.contains("Property [Architectures] expected type: JSONArray, found: String"));
}
/** Measured on AWS (eu-west-1, 2026-10-19): a member nested in a property is typed too. */
@Test
@DisplayName("a VpcConfig whose SubnetIds is a string fails the stack")
void aNestedMemberOfTheWrongTypeFailsTheStack() throws InterruptedException {
cfn.createStack(request -> request.stackName(NESTED_STACK).templateBody(
template("\"VpcConfig\": {\"SubnetIds\": \"subnet-0123456789abcdef0\", \"SecurityGroupIds\": []}")));
assertThat(TestFixtures.awaitStackTerminal(cfn, NESTED_STACK, DEPLOY_TIMEOUT)).isEqualTo("ROLLBACK_COMPLETE");
assertThat(reasons(NESTED_STACK)).anyMatch(reason ->
reason.contains("Property [SubnetIds] expected type: JSONArray, found: String"));
}
private static List<String> reasons(String stackName) {
if (TestFixtures.isRealAws()) {
return cfn.describeEvents(request -> request.stackName(stackName)).operationEvents().stream()