refactor(cloudformation): move the SecretsManager types into per-service provisioners (#3530)

Moves AWS::SecretsManager::Secret and AWS::SecretsManager::SecretTargetAttachment
out of the monolith switch. The logic is carried over intact. What differs is the
plumbing, plus the style the new files have to meet as new files: locals that were
var now name their types, which matters most where an RDS and a DocumentDB lookup
sit side by side returning different shapes, the inline fully-qualified
ObjectMapper, ObjectNode and RandomPasswordGenerator are imported, and neither file
keeps a private copy of resolveOptional now that ProvisionContext already offers the
identical method the other 46 migrated provisioners call. Monolith 5,461 to 4,987
lines, legacy types 33 to 31.

Two classes rather than one, because the two types do not want the same
dependencies. The secret needs only SecretsManagerService. The attachment reads
an RDS or DocumentDB endpoint to build the connection detail it writes into the
target secret, so it needs three services and an ObjectMapper. Splitting keeps
AGENTS.md's "inject only the service it wraps" true for the common case and
confines the wide dependency to the type that genuinely has it. The repo already
anticipated the split: SecretTargetAttachmentCfnProvisionerTest has existed for
some time, named for a class that did not.

This is the batch that finally takes RdsService out of the monolith. Batch 7
could not: dbInstanceConnection and dbClusterConnection were the last two
rdsService call sites and both belong to the attachment. Three service fields
leave with this change, SecretsManagerService, RdsService and DocDbService, along
with their constructor parameters and imports, plus six RDS model imports that
batch 7 left behind unused.

SecretTargetAttachment is the first extracted type to leave
DELETE_NEEDS_STACK_RESOURCE, which drops from 7 entries to 6. Its delete needs
two create-time attributes no physical id carries: which secret fields the
attachment managed, so only those are stripped, and which attachment owns the
secret, so a second attachment's fields survive. That logic moves into the
provisioner's delete(StackResource, String) override, and the set entry goes in
the same commit because the registry is consulted first and leaving both claiming
the type is exactly what CfnDeletePrecedenceTest exists to catch. The id-only
delete keeps refusing the attachment with the same message, which a test asserts.

The 34 SecretTargetAttachmentCfnProvisionerTest tests and the 5 attachment
integration tests pass unchanged, which is the guard that the move preserved
behaviour: both build through CfnProvisionerFixture, so they exercise the new
provisioners without knowing they exist.

Making the types provisioner-owned rather than LEGACY_SWITCH puts them under
CfnSchemaCoverageTest for the first time, since it skips switch-owned types. One
attribute surfaces: Fn::GetAtt Id on a secret is its ARN, which the provisioner
already sets as the physical id and as Arn. It is recorded as a gap rather than
set, to keep this commit a pure move.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-09-13 14:22:54 -05:00
1 parent 7d96799c5a
commit d90cb23c23
6 files changed
+614 -479

No files matched your search

@@ -66,6 +66,8 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.RdsCfnPro
import io.github.hectorvent.floci.services.cloudformation.provisioners.Route53CfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.S3CfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.SchedulerScheduleGroupCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.SecretTargetAttachmentCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.SecretsManagerCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.SnsCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.SsmCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceProvisioner;
@@ -321,6 +323,11 @@ final class CfnProvisionerFixture {
if (rdsService != null) {
discovered.add(new RdsCfnProvisioner(rdsService, dynamicReferences));
}
if (secretsManagerService != null) {
discovered.add(new SecretsManagerCfnProvisioner(secretsManagerService));
discovered.add(new SecretTargetAttachmentCfnProvisioner(
secretsManagerService, rdsService, docDbService, objectMapper));
}
if (wafV2Service != null) {
discovered.add(new WafV2CfnProvisioner(wafV2Service));
}
@@ -626,7 +633,6 @@ final class CfnProvisionerFixture {
iamService,
ssmService,
kmsService,
secretsManagerService,
apiGatewayService,
apiGatewayV2Service,
ecrService,
@@ -637,14 +643,12 @@ final class CfnProvisionerFixture {
reachableEndpoint,
stepFunctionsService,
ec2Service,
rdsService,
eksService,
logsService,
kinesisService,
cloudWatchMetricsService,
autoScalingService,
firehoseService,
docDbService,
cloudFrontService,
resourceRegistry,
dynamicReferences,