mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(cloudformation): move AWS::Route53::RecordSet into Route53CfnProvisioner (#3724)
* refactor(cloudformation): move AWS::Route53::RecordSet into Route53CfnProvisioner The record set leaves CloudFormationResourceProvisioner for the provisioner that already owns AWS::Route53::HostedZone, which gains a type switch in provision and delete; the hosted-zone path is untouched. The record-set arm keeps the legacy behaviour exactly, a name-only resource whose Ref is the resolved Name or a generated record- id, and now also publishes Id, the registry schema's only read-only property, which Fn::GetAtt could never resolve before. Its delete logs the same warning the legacy default arm did, since nothing was ever written for the record. Writing the record through ChangeResourceRecordSets and enforcing the schema's required Type and Name are follow-ups, not part of the move. The legacy switch goes from 24 to 23 types and the monolith loses its last Route53 reference. * refactor(cloudformation): keep AWS::Route53::RecordSet free of GetAtt attributes The move published Id because the schema coverage gate asks for every read-only property in the registry schema. That schema has no handlers: RecordSet is a legacy type, and the CloudFormation resource specification gives it no attributes, so Ref stays its only reference, as it was in the legacy provisioner. Id is recorded in getatt-attribute-gaps.tsv instead.
This commit is contained in:
1 parent
f7565dff3e
commit
9cd27190ff
6 files changed
+243
-11
No files matched your search
+134
@@ -0,0 +1,134 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* {@code AWS::Route53::RecordSet} through the per-service provisioner: {@code Ref} is the record
|
||||
* name. It is read back through an SSM parameter the template writes, because a stack status
|
||||
* alone proves nothing: an unowned type is stubbed CREATE_COMPLETE with an {@code arn:aws:stub}
|
||||
* physical id, which the parameter would expose.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationRoute53RecordSetIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request";
|
||||
private static final String SSM_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/ssm/aws4_request";
|
||||
private static final Duration STACK_DELETE_TIMEOUT = Duration.ofSeconds(30);
|
||||
private static final Duration STACK_DELETE_POLL_INTERVAL = Duration.ofMillis(50);
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordSetRefResolvesToTheRecordName() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "r53-recordset-" + suffix;
|
||||
String recordName = "www." + suffix + ".cfn-it.example.com";
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"Zone": {
|
||||
"Type": "AWS::Route53::HostedZone",
|
||||
"Properties": {"Name": "%s.cfn-it.example.com"}
|
||||
},
|
||||
"Www": {
|
||||
"Type": "AWS::Route53::RecordSet",
|
||||
"Properties": {
|
||||
"HostedZoneId": {"Ref": "Zone"},
|
||||
"Name": "%s",
|
||||
"Type": "A",
|
||||
"TTL": "300",
|
||||
"ResourceRecords": ["10.0.0.1"]
|
||||
}
|
||||
},
|
||||
"RefParam": {
|
||||
"Type": "AWS::SSM::Parameter",
|
||||
"Properties": {"Name": "/r53-recordset/%s/ref", "Type": "String", "Value": {"Ref": "Www"}}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".formatted(suffix, recordName, suffix);
|
||||
|
||||
createStack(stackName, template);
|
||||
assertStackStatus(stackName, "CREATE_COMPLETE");
|
||||
try {
|
||||
assertEquals(recordName, parameterValue("/r53-recordset/" + suffix + "/ref"));
|
||||
} finally {
|
||||
deleteStack(stackName);
|
||||
awaitStackGone(stackName);
|
||||
}
|
||||
}
|
||||
|
||||
private void createStack(String stackName, String template) {
|
||||
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);
|
||||
}
|
||||
|
||||
private void assertStackStatus(String stackName, String status) {
|
||||
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>" + status + "</StackStatus>"));
|
||||
}
|
||||
|
||||
private void deleteStack(String stackName) {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DeleteStack")
|
||||
.formParam("StackName", stackName)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
private String parameterValue(String name) {
|
||||
return given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("Authorization", SSM_AUTH)
|
||||
.header("X-Amz-Target", "AmazonSSM.GetParameter")
|
||||
.body("{\"Name\":\"" + name + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("Parameter.Value");
|
||||
}
|
||||
|
||||
private void awaitStackGone(String stackName) {
|
||||
await()
|
||||
.atMost(STACK_DELETE_TIMEOUT)
|
||||
.pollInterval(STACK_DELETE_POLL_INTERVAL)
|
||||
.untilAsserted(() -> {
|
||||
String body = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when().post("/").then().extract().asString();
|
||||
if (body.contains("<StackStatus>DELETE_FAILED</StackStatus>")) {
|
||||
fail("stack delete failed: " + body);
|
||||
}
|
||||
assertTrue(body.contains("does not exist"), "stack still exists: " + body);
|
||||
});
|
||||
}
|
||||
}
|
||||
+62
@@ -15,6 +15,7 @@ import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
@@ -22,6 +23,7 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class Route53CfnProvisionerTest {
|
||||
@@ -366,4 +368,64 @@ class Route53CfnProvisionerTest {
|
||||
+ "(tracked zone missing), so the generic rollback walker must treat this "
|
||||
+ "resource as restored instead of failing rollback as unimplemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordSetUsesItsNameAsRefPublishesNoAttributesAndWritesNothingToTheZone() {
|
||||
Route53Service service = mock(Route53Service.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode props = mapper.createObjectNode()
|
||||
.put("HostedZoneId", "Z123456789")
|
||||
.put("Name", "www.example.com")
|
||||
.put("Type", "A");
|
||||
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
|
||||
when(engine.resolve(any())).thenAnswer(invocation -> invocation.<JsonNode>getArgument(0).asText());
|
||||
ProvisionContext context = new ProvisionContext(engine, "us-east-1", "623666680275", "dns-stack");
|
||||
StackResource resource = new StackResource();
|
||||
resource.setLogicalId("Alias");
|
||||
resource.setResourceType("AWS::Route53::RecordSet");
|
||||
|
||||
new Route53CfnProvisioner(service).provision(resource, props, context);
|
||||
|
||||
assertEquals("www.example.com", resource.getPhysicalId());
|
||||
assertEquals(Set.of(), resource.getAttributes().keySet());
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordSetWithoutANameGetsAGeneratedRecordId() {
|
||||
Route53Service service = mock(Route53Service.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode props = mapper.createObjectNode().put("Type", "A");
|
||||
CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
|
||||
when(engine.resolve(any())).thenAnswer(invocation -> invocation.<JsonNode>getArgument(0).asText());
|
||||
ProvisionContext context = new ProvisionContext(engine, "us-east-1", "623666680275", "dns-stack");
|
||||
StackResource resource = new StackResource();
|
||||
resource.setLogicalId("Alias");
|
||||
resource.setResourceType("AWS::Route53::RecordSet");
|
||||
|
||||
new Route53CfnProvisioner(service).provision(resource, props, context);
|
||||
|
||||
assertNotNull(resource.getPhysicalId());
|
||||
assertTrue(resource.getPhysicalId().matches("record-[0-9a-f]{8}"), resource.getPhysicalId());
|
||||
assertTrue(resource.getAttributes().isEmpty(), resource.getAttributes().toString());
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingARecordSetLeavesHostedZonesAlone() {
|
||||
Route53Service service = mock(Route53Service.class);
|
||||
|
||||
new Route53CfnProvisioner(service).delete("AWS::Route53::RecordSet", "www.example.com", "us-east-1");
|
||||
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAHostedZoneStillDeletesTheZone() {
|
||||
Route53Service service = mock(Route53Service.class);
|
||||
|
||||
new Route53CfnProvisioner(service).delete("AWS::Route53::HostedZone", "Z123456789", "us-east-1");
|
||||
|
||||
verify(service).deleteHostedZone("Z123456789");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user