mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(cloudformation): set Fn::GetAtt attributes the schemas declare (#2761)
* fix(cloudformation): set Fn::GetAtt attributes the schemas declare An attribute a provisioner never sets is invisible at runtime: GetAtt resolution returns the literal "LogicalId.Attr" when a resource has no such attribute, so a template referencing one receives that string as a value instead of failing. Auditing every migrated type against its registry schema found 24 such attributes across 15 types. Sets the three whose correct value is unambiguous: AWS::SNS::Topic gains TopicArn, the attribute aws-sns-topic.json actually declares. Arn stays alongside it, since templates written against earlier releases reference it. AWS::S3::Bucket gains DualStackDomainName, in the same form as the RegionalDomainName it already builds. AWS::CodePipeline::Pipeline gains Arn, which the schema describes as the pipeline's ARN and which is constructible from the region, account and name already in hand. The remaining 21 are recorded in getatt-attribute-gaps.tsv, each with a reason. Most are attributes Floci cannot set because it does not emulate the behaviour behind them, such as VPC CIDR associations or pipe lifecycle timestamps. A few are simply undecidable from the schema alone, and inventing a value would be worse than leaving the gap recorded. CfnSchemaCoverageTest makes the set a ratchet rather than a snapshot: closing a gap requires deleting its row, introducing one requires adding a row with a reason where a reviewer sees it, and a row that stops being real fails until it is removed. * test(cloudformation): await the async stack operations in the VPC gateway test The test asserted the results of CreateStack and DeleteStack immediately. Both are asynchronous: CloudFormationService submits them to a background executor and the HTTP call returns as soon as the work is queued, so each assertion only passed while the executor happened to win the race. The delete assertion lost that race on CI. Adding a test class elsewhere in the suite re-partitioned the deterministic CI shards, which moved this class to different neighbours and changed the timing it had been relying on. Both assertions now poll to a deadline, matching the awaitStackStatus pattern the other CloudFormation integration tests use. A genuinely unperformed detach still fails, just ten seconds later, so this removes the timing sensitivity without hiding a real regression. * fix(cloudformation): scope the GetAtt coverage scan per resource type The scan read each provisioner as a whole file, so a class serving several types credited every one of them with what any single arm sets. That is a false negative in the only direction that matters: the gap the ratchet exists to record stops being reported. It was hiding a real one. Ec2NetworkAclCfnProvisioner sets Id for NetworkAcl and never for NetworkAclEntry, whose schema declares Id as its primaryIdentifier and sole readOnlyProperty, so Fn::GetAtt on it resolved to the literal "LogicalId.Id" while the audit reported clean. Set it to the composite physical id so the attribute agrees with Ref. The scan now walks the switch on getResourceType() in provision, takes each arm plus the same-class methods it transitively calls, and adds whatever provision writes outside the switch to every type, since that is the shared path. Two shapes need the care: - Only a switch in statement position is a dispatch. A switch expression such as `boolean ingress = switch (r.getResourceType())` picks a value on one shared path. Reading its arms as per-type paths reported SecurityGroupIngress and SecurityGroupEgress Id as gaps when both are set after the switch. - A class with a dispatch switch but no arm for a type it owns now fails the scan, so an unrecognised shape cannot quietly fall back to the class-wide reading it replaced. Raised by pgermosen in review.
This commit is contained in:
1 parent
cf10d25ac2
commit
7095641e25
10 files changed
+506
-16
No files matched your search
+3
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation.provisioners;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
@@ -194,6 +195,8 @@ public class CodePipelineCfnProvisioner implements CfnResourceProvisioner {
|
||||
delete("AWS::CodePipeline::Pipeline", previousPhysicalId, ctx.region());
|
||||
}
|
||||
r.setPhysicalId(name);
|
||||
r.getAttributes().put("Arn",
|
||||
AwsArnUtils.Arn.of("codepipeline", ctx.region(), ctx.accountId(), name).toString());
|
||||
r.getAttributes().put("Version",
|
||||
String.valueOf(response.path("pipeline").path("version").asInt(1)));
|
||||
}
|
||||
|
||||
+6
-1
@@ -108,7 +108,12 @@ public class Ec2NetworkAclCfnProvisioner implements CfnResourceProvisioner {
|
||||
// the same key is an update. replace=false would raise NetworkAclEntryAlreadyExists
|
||||
// on every stack update.
|
||||
from, to, true);
|
||||
r.setPhysicalId(aclId + "|" + ruleNumber + "|" + (egress ? "egress" : "ingress"));
|
||||
String entryId = aclId + "|" + ruleNumber + "|" + (egress ? "egress" : "ingress");
|
||||
r.setPhysicalId(entryId);
|
||||
// Id is the type's primaryIdentifier and its only readOnlyProperty, so Fn::GetAtt Id must
|
||||
// agree with what Ref returns. Without it the reference resolves to the literal
|
||||
// "LogicalId.Id", which reads as a successful lookup.
|
||||
r.getAttributes().put("Id", entryId);
|
||||
}
|
||||
|
||||
private void provisionSubnetNetworkAclAssociation(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
|
||||
+2
@@ -58,6 +58,8 @@ public class S3CfnProvisioner implements CfnResourceProvisioner {
|
||||
r.getAttributes().put("Arn", AwsArnUtils.Arn.of("s3", "", "", bucketName).toString());
|
||||
r.getAttributes().put("DomainName", bucketName + ".s3.amazonaws.com");
|
||||
r.getAttributes().put("RegionalDomainName", bucketName + ".s3." + ctx.region() + ".amazonaws.com");
|
||||
r.getAttributes().put("DualStackDomainName",
|
||||
bucketName + ".s3.dualstack." + ctx.region() + ".amazonaws.com");
|
||||
r.getAttributes().put("WebsiteURL",
|
||||
"http://" + bucketName + ".s3-website." + ctx.region() + ".amazonaws.com");
|
||||
r.getAttributes().put("BucketName", bucketName);
|
||||
|
||||
+3
@@ -53,6 +53,9 @@ public class SnsCfnProvisioner implements CfnResourceProvisioner {
|
||||
var topic = snsService.createTopic(topicName, attributes, Map.of(), ctx.region());
|
||||
// Ref returns the topic ARN, which is why the physical id is the ARN and not the name.
|
||||
r.setPhysicalId(topic.getTopicArn());
|
||||
// TopicArn is the attribute aws-sns-topic.json declares read-only. Arn is kept alongside it
|
||||
// because templates written against earlier Floci releases already reference it.
|
||||
r.getAttributes().put("TopicArn", topic.getTopicArn());
|
||||
r.getAttributes().put("Arn", topic.getTopicArn());
|
||||
r.getAttributes().put("TopicName", topicName);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user