Light, fluffy, and always free - The AWS Local Emulator alternative
fix(cloudformation): publish RuleName and the RDS group ARNs the current registry schemas declare (#4135)
Hector Venturaa0e3b6b674c1
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EventsCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EventsCfnProvisioner.javaindex f5ef89eeaa..59b5c959de 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EventsCfnProvisioner.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EventsCfnProvisioner.java@@ -141,6 +141,7 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {state, description, roleArn, Map.of(), ctx.region());r.setPhysicalId(ruleName);r.getAttributes().put("Arn", rule.getArn());+ r.getAttributes().put("RuleName", ruleName);// A rule on a custom bus is keyed by that bus; remember it so the resource delete can target// the right bus (the physical id is only the rule name, which resolves to the default bus).if (busName != null && !busName.isBlank()) {diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RdsCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RdsCfnProvisioner.javaindex 1b3e2d902a..04b28e5b64 100644--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RdsCfnProvisioner.java+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RdsCfnProvisioner.java@@ -222,6 +222,9 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {}r.setPhysicalId(group.getDbSubnetGroupName());r.getAttributes().put("DBSubnetGroupName", group.getDbSubnetGroupName());+ if (group.getDbSubnetGroupArn() != null) {+ r.getAttributes().put("DBSubnetGroupArn", group.getDbSubnetGroupArn());+ }}private void provisionDbParameterGroup(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,@@ -254,6 +257,9 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {}r.setPhysicalId(group.getDbParameterGroupName());r.getAttributes().put("DBParameterGroupName", group.getDbParameterGroupName());+ if (group.getDbParameterGroupArn() != null) {+ r.getAttributes().put("DBParameterGroupArn", group.getDbParameterGroupArn());+ }}private void provisionDbClusterParameterGroup(StackResource r, JsonNode props,diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEventBusIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEventBusIntegrationTest.javaindex 220295bfe5..ea05bfe6b5 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEventBusIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEventBusIntegrationTest.java@@ -1,5 +1,6 @@package io.github.hectorvent.floci.services.cloudformation;+import io.github.hectorvent.floci.core.common.XmlParser;import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;import io.quarkus.test.junit.QuarkusTest;import org.junit.jupiter.api.BeforeAll;@@ -7,8 +8,11 @@ import org.junit.jupiter.api.Test;import org.junit.jupiter.params.ParameterizedTest;import org.junit.jupiter.params.provider.ValueSource;+import java.util.Map;+import static io.restassured.RestAssured.given;import static org.hamcrest.Matchers.containsString;+import static org.junit.jupiter.api.Assertions.assertEquals;/*** Verifies CloudFormation provisions {@code AWS::Events::EventBus} as a real custom EventBridge bus.@@ -297,6 +301,59 @@ class CloudFormationEventBusIntegrationTest {.body(containsString("ResourceNotFoundException"));}+ @Test+ void getAttRuleNameResolvesToTheRuleName() throws InterruptedException {+ String suffix = Long.toString(System.nanoTime(), 36);+ String ruleName = "cfn-rulename-" + suffix;+ String stackName = "rulename-stack-" + suffix;+ String template = """+ {+ "Resources": {+ "Named": {+ "Type": "AWS::Events::Rule",+ "Properties": {+ "Name": "%s",+ "EventPattern": { "source": ["com.example.orders"] }+ }+ },+ "Unnamed": {+ "Type": "AWS::Events::Rule",+ "Properties": {+ "EventPattern": { "source": ["com.example.orders"] }+ }+ }+ },+ "Outputs": {+ "NamedRuleName": { "Value": { "Fn::GetAtt": ["Named", "RuleName"] } },+ "UnnamedRuleName": { "Value": { "Fn::GetAtt": ["Unnamed", "RuleName"] } },+ "UnnamedRef": { "Value": { "Ref": "Unnamed" } }+ }+ }+ """.formatted(ruleName);++ createStack(stackName, template);+ try {+ assertStackStatus(stackName, "CREATE_COMPLETE");+ String xml = given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", CFN_AUTH)+ .formParam("Action", "DescribeStacks")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .extract().asString();+ Map<String, String> outputs = XmlParser.extractPairs(xml, "Outputs", "OutputKey", "OutputValue");++ assertEquals(ruleName, outputs.get("NamedRuleName"));+ assertEquals(outputs.get("UnnamedRef"), outputs.get("UnnamedRuleName"));+ } finally {+ deleteStack(stackName);+ awaitStackDeleted(stackName);+ }+ }+private void awaitStackDeleted(String stackName) throws InterruptedException {String lastBody = null;for (int i = 0; i < 100; i++) {diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsIntegrationTest.javaindex 768e1915b3..9e130a2c1b 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationRdsIntegrationTest.java@@ -5,6 +5,8 @@ import io.github.hectorvent.floci.services.ec2.Ec2Service;import io.quarkus.test.junit.QuarkusTest;import org.junit.jupiter.api.Test;+import java.util.Map;+import static io.restassured.RestAssured.given;import static org.hamcrest.Matchers.containsString;import static org.hamcrest.Matchers.not;@@ -162,6 +164,82 @@ class CloudFormationRdsIntegrationTest {.body(containsString(groupName));}+ @Test+ void getAttResolvesTheSubnetAndParameterGroupArns() {+ String suffix = Long.toString(System.nanoTime(), 36);+ String subnetGroupName = "cfn-rds-arn-subnets-" + suffix;+ String parameterGroupName = "cfn-rds-arn-params-" + suffix;+ String stackName = "cfn-rds-arn-stack-" + suffix;+ String template = """+ {+ "Resources": {+ "DbSubnets": {+ "Type": "AWS::RDS::DBSubnetGroup",+ "Properties": {+ "DBSubnetGroupName": "%s",+ "DBSubnetGroupDescription": "managed by cfn",+ "SubnetIds": ["%s", "%s"]+ }+ },+ "DbParams": {+ "Type": "AWS::RDS::DBParameterGroup",+ "Properties": {+ "DBParameterGroupName": "%s",+ "Family": "postgres16",+ "Description": "managed by cfn"+ }+ }+ },+ "Outputs": {+ "SubnetGroupArn": {"Value": {"Fn::GetAtt": ["DbSubnets", "DBSubnetGroupArn"]}},+ "ParameterGroupArn": {"Value": {"Fn::GetAtt": ["DbParams", "DBParameterGroupArn"]}}+ }+ }+ """.formatted(subnetGroupName, Ec2Service.defaultSubnetId("us-east-1", "a"),+ Ec2Service.defaultSubnetId("us-east-1", "b"), parameterGroupName);++ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", CFN_AUTH)+ .formParam("Action", "CreateStack")+ .formParam("StackName", stackName)+ .formParam("TemplateBody", template)+ .when()+ .post("/")+ .then()+ .statusCode(200);++ try {+ String xml = given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", CFN_AUTH)+ .formParam("Action", "DescribeStacks")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))+ .extract().asString();+ Map<String, String> outputs = XmlParser.extractPairs(xml, "Outputs", "OutputKey", "OutputValue");++ assertEquals("arn:aws:rds:us-east-1:000000000000:subgrp:" + subnetGroupName,+ outputs.get("SubnetGroupArn"));+ assertEquals("arn:aws:rds:us-east-1:000000000000:pg:" + parameterGroupName,+ outputs.get("ParameterGroupArn"));+ } finally {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", CFN_AUTH)+ .formParam("Action", "DeleteStack")+ .formParam("StackName", stackName)+ .when()+ .post("/")+ .then()+ .statusCode(200);+ }+ }+private static String dbSubnetGroupTemplate(String groupName) {return """{diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.javaindex 343948dee5..5eb57ddd70 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java@@ -876,6 +876,7 @@ class RdsCfnProvisionerTest {void provisionsDbSubnetGroupWithResolvedSubnetIds() {DbSubnetGroup group = mock(DbSubnetGroup.class);when(group.getDbSubnetGroupName()).thenReturn("my-subnet-group");+ when(group.getDbSubnetGroupArn()).thenReturn("arn:aws:rds:us-east-1:000000000000:subgrp:my-subnet-group");when(rdsService.createDbSubnetGroup(any(), any(), anyList(), any())).thenReturn(group);StackResource r = provision("Sg", "AWS::RDS::DBSubnetGroup", """@@ -885,6 +886,8 @@ class RdsCfnProvisionerTest {assertEquals("my-subnet-group", r.getPhysicalId());assertEquals("my-subnet-group", r.getAttributes().get("DBSubnetGroupName"));+ assertEquals("arn:aws:rds:us-east-1:000000000000:subgrp:my-subnet-group",+ r.getAttributes().get("DBSubnetGroupArn"));verify(rdsService).createDbSubnetGroup("my-subnet-group", "db subnets",List.of("subnet-a", "subnet-b"), "us-east-1");}@@ -989,6 +992,7 @@ class RdsCfnProvisionerTest {void provisionsDbParameterGroup() {DbParameterGroup group = mock(DbParameterGroup.class);when(group.getDbParameterGroupName()).thenReturn("my-pg");+ when(group.getDbParameterGroupArn()).thenReturn("arn:aws:rds:us-east-1:000000000000:pg:my-pg");when(rdsService.createDbParameterGroup(any(), any(), any(), any())).thenReturn(group);StackResource r = provision("Pg", "AWS::RDS::DBParameterGroup", """@@ -997,6 +1001,7 @@ class RdsCfnProvisionerTest {assertEquals("my-pg", r.getPhysicalId());assertEquals("my-pg", r.getAttributes().get("DBParameterGroupName"));+ assertEquals("arn:aws:rds:us-east-1:000000000000:pg:my-pg", r.getAttributes().get("DBParameterGroupArn"));verify(rdsService).createDbParameterGroup("my-pg", "postgres16", "params", "us-east-1");}diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EventsCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EventsCfnProvisionerTest.javaindex 8ac521a72e..4db763dd23 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EventsCfnProvisionerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EventsCfnProvisionerTest.java@@ -87,6 +87,7 @@ class EventsCfnProvisionerTest {provisioner.provision(r, mapper.createObjectNode(), ctx("my-stack-Rule-ab12cd"));assertEquals("my-stack-Rule-ab12cd", r.getPhysicalId());+ assertEquals("my-stack-Rule-ab12cd", r.getAttributes().get("RuleName"));verify(events).putRule(eq("my-stack-Rule-ab12cd"), any(), any(), any(), any(), any(), any(),any(), anyString());}@@ -100,6 +101,7 @@ class EventsCfnProvisionerTest {assertEquals("orders", r.getPhysicalId());assertEquals(RULE_ARN, r.getAttributes().get("Arn"));+ assertEquals("orders", r.getAttributes().get("RuleName"));}// ── targets are driven to the template's desired state ───────────────────diff --git a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv b/src/test/resources/cloudformation/getatt-attribute-gaps.tsvindex 8cb937051f..0564a620df 100644--- a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv+++ b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv@@ -1,5 +1,4 @@AWS::AppSync::GraphQLApi GraphQLEndpointArn the private-endpoint ARN of the GraphQL endpoint; Floci serves one public endpoint and has no private-endpoint model-AWS::CertificateManager::Certificate Id schema gives no description; Ref returns the ARN and the legacy spec gives the type no attributesAWS::CodeBuild::Project Id schema gives no description; AWS's Id may differ from the project name Floci usesAWS::CodePipeline::CustomActionType Id schema gives no description; the custom action has no separate id in FlociAWS::CodePipeline::Webhook Id schema gives no description; Floci keys webhooks by name@@ -46,8 +45,9 @@ AWS::RDS::DBInstance ReadReplicaDBInstanceIdentifiers read replicas are not emulAWS::RDS::DBInstance ResumeFullAutomationModeTime RDS Custom automation mode is not emulatedAWS::RDS::DBInstance SecondaryAvailabilityZone multi-AZ secondary placement is not emulatedAWS::RDS::DBInstance StatusInfos read-replica status detail is not emulated+AWS::RDS::DBInstance StorageOperationPercentProgress storage operations (scaling, type changes) are not emulated; storage changes apply synchronously+AWS::RDS::DBInstance StorageOperationStatus storage operations (scaling, type changes) are not emulated; storage changes apply synchronouslyAWS::Redshift::Cluster DeferMaintenanceIdentifier Floci does not emulate deferred maintenance windows-AWS::Route53::RecordSet Id schema gives no description; Ref returns the record name and the legacy spec gives the type no attributesAWS::SQS::QueuePolicy Id schema gives no description; the policy has no backing entity to take an id fromAWS::SecretsManager::Secret Id Fn::GetAtt Id on a secret is its ARN, which the provisioner already sets as the physical id and as Arn; closable, deferred to a follow-up PR to keep this one a pure moveAWS::EKS::Cluster ClusterSecurityGroupId not modeled: Floci does not create a cluster security group, so there is no id to publish