refactor(cloudformation): replace the retired monolith with CfnResourceDispatcher (#4269)

* refactor(cloudformation): replace the retired monolith with CfnResourceDispatcher

CloudFormationResourceProvisioner was the monolith that held every AWS::
provisioning arm. With the per-service migration complete it kept no arm:
LEGACY_SWITCH_TYPES and DELETE_NEEDS_STACK_RESOURCE were empty sets, five
private helpers duplicated ProvisionContext, six imports were unused, and its
UPDATE_ROLLBACK_* constants only re-exported CfnRollback. What it still did is
small: route provision and delete to the registry, stub a type nothing serves
(or refuse it in strict mode), answer the engine's update-lifecycle questions
through the owning provisioner, and give Cloud Control its stack-less entry
points.

That is now CfnResourceDispatcher in provisioners/, behaviour unchanged: the
same stub arm, warn lines, status reasons and strict-mode failure, with the
same logger category the unsupported-type test binds to. The dead overloads
go with the class (the 8-arg provision, the unused accountId on delete, the
short deleteStandalone forms). CloudFormationTemplateEngine gains a public
standalone(...) factory so the dispatcher can build Cloud Control's throwaway
engine from outside the package while the constructors stay package-private
for the tests that mock it. CloudFormationService reads the rollback markers
from CfnRollback directly.

The empty guards leave with the class: CfnDeletePrecedenceTest read only the
empty set, and CfnResourceInventoryTest no longer folds a legacy owner into
the inventory (the checked-in file had no such row). Javadocs that described
the switch as still present now describe the registry.

CfnResourceDispatcherTest pins the standalone engine's dynamic-reference
resolver, the prior identity reaching the ProvisionContext, and the
whole-resource delete form; every other test only changed the type it names.

* chore(cloudformation): retire the legacy-switch guards from tooling and instructions

The switch is gone, so nothing can carry a LEGACY_SWITCH owner: the schema
coverage test drops its skip, the docs generator's double-ownership check
generalises to any type with two provisioners, and its fixtures name real
owners. AGENTS.md and CONTRIBUTING.md tell contributors where types live
instead of warning them off a class that no longer exists.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-09-23 22:31:27 -04:00
1 parent 239f560d97
commit 69ceb976c7
68 files changed
+590 -673

No files matched your search

@@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationResourceProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.model.Tag;
@@ -33,7 +33,7 @@ class CloudControlServiceTest {
@Test
void accountScopesCreateStatusLookupAndDelete() throws Exception {
CloudFormationResourceProvisioner provisioner = mock(CloudFormationResourceProvisioner.class);
CfnResourceDispatcher provisioner = mock(CfnResourceDispatcher.class);
StackResource resource = new StackResource();
resource.setPhysicalId("vpc-account-a");
resource.setAttributes(Map.of("VpcId", "vpc-account-a"));
@@ -61,20 +61,18 @@ class CloudControlServiceTest {
CloudControlService.ProgressEvent deniedDelete = service.deleteResource(
"us-east-1", "222222222222", "AWS::EC2::VPC", "vpc-account-a");
assertEquals("FAILED", deniedDelete.operationStatus());
verify(provisioner, never()).deleteStandalone(anyString(),
anyString(), anyString(),
anyString(), anyMap());
verify(provisioner, never()).deleteStandalone(anyString(), anyString(), anyString(), anyMap());
CloudControlService.ProgressEvent deleted = service.deleteResource(
"us-east-1", "111111111111", "AWS::EC2::VPC", "vpc-account-a");
assertEquals("SUCCESS", deleted.operationStatus());
verify(provisioner).deleteStandalone("AWS::EC2::VPC", "vpc-account-a", "us-east-1",
"111111111111", Map.of("VpcId", "vpc-account-a"));
Map.of("VpcId", "vpc-account-a"));
}
@Test
void restoresAccountOwnersAndRequestStateFromMetadataStores() throws Exception {
CloudFormationResourceProvisioner provisioner = mock(CloudFormationResourceProvisioner.class);
CfnResourceDispatcher provisioner = mock(CfnResourceDispatcher.class);
StackResource resource = new StackResource();
resource.setPhysicalId("igw-persisted");
when(provisioner.provisionStandalone(eq("AWS::EC2::InternetGateway"),
@@ -120,7 +118,7 @@ class CloudControlServiceTest {
ObjectMapper mapper = new ObjectMapper();
CloudControlService service = new CloudControlService(
mock(S3Service.class), ec2Service, mock(IamService.class),
mock(CloudFormationResourceProvisioner.class), mapper);
mock(CfnResourceDispatcher.class), mapper);
String properties = service.listResources("us-east-1", "AWS::EC2::VPC").getFirst().properties();
JsonNode tags = mapper.readTree(properties).path("Tags");
@@ -140,7 +138,7 @@ class CloudControlServiceTest {
void listResourcesRejectsARealButUnbackedTypeInsteadOfReturningEmpty() {
CloudControlService service = new CloudControlService(
mock(S3Service.class), mock(Ec2Service.class), mock(IamService.class),
mock(CloudFormationResourceProvisioner.class), new ObjectMapper());
mock(CfnResourceDispatcher.class), new ObjectMapper());
AwsException e = assertThrows(AwsException.class,
() -> service.listResources("us-east-1", "AWS::SQS::Queue"));
@@ -153,7 +151,7 @@ class CloudControlServiceTest {
void listResourcesRejectsATypeThatDoesNotExistInAwsAtAll() {
CloudControlService service = new CloudControlService(
mock(S3Service.class), mock(Ec2Service.class), mock(IamService.class),
mock(CloudFormationResourceProvisioner.class), new ObjectMapper());
mock(CfnResourceDispatcher.class), new ObjectMapper());
AwsException e = assertThrows(AwsException.class,
() -> service.listResources("us-east-1", "AWS::NoSuch::Type"));
@@ -168,7 +166,7 @@ class CloudControlServiceTest {
when(s3Service.listBuckets()).thenReturn(List.of());
CloudControlService service = new CloudControlService(
s3Service, mock(Ec2Service.class), mock(IamService.class),
mock(CloudFormationResourceProvisioner.class), new ObjectMapper());
mock(CfnResourceDispatcher.class), new ObjectMapper());
assertTrue(service.listResources("us-east-1", "AWS::S3::Bucket").isEmpty());
}
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.apigatewayv2.model.Authorizer;
import io.github.hectorvent.floci.services.apigatewayv2.model.Route;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.ApiGatewayV2CfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CloudFormationResourceRegistry;
import io.github.hectorvent.floci.services.s3.S3Service;
import org.junit.jupiter.api.BeforeEach;
@@ -37,7 +38,7 @@ class ApiGatewayV2CfnProvisionerTest {
private static final String API_ID = "api-123";
private final ObjectMapper mapper = new ObjectMapper();
private ApiGatewayV2Service apiGatewayV2Service;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -1,64 +0,0 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CloudFormationResourceRegistry;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Guards the delete dispatch order in {@link CloudFormationResourceProvisioner}.
*
* <p>Deleting a resource takes one of three routes: an extracted provisioner, the attribute-aware
* branches for {@code DELETE_NEEDS_STACK_RESOURCE}, or the generic type/physicalId switch. The
* registry is consulted first so an exact match beats the {@code Custom::} prefix branch, which is
* what lets {@code Custom::DynamoDBReplica} move to a provisioner at all.
*
* <p>The cost of registry-first is that a leftover attribute-aware branch for a migrated type
* becomes unreachable rather than wrong. That is the safe direction, but it would let a slice quietly
* drop delete logic that only that branch implemented, so this test makes the overlap a build
* failure: migrating one of those types must move its logic into the provisioner's
* {@code delete(StackResource, String)} override and drop its entry from the set.
*/
@QuarkusTest
class CfnDeletePrecedenceTest {
@Inject
CloudFormationResourceRegistry registry;
@Test
void noTypeIsServedByBothAProvisionerAndAnAttributeAwareBranch() {
List<String> both = CloudFormationResourceProvisioner.DELETE_NEEDS_STACK_RESOURCE.stream()
.filter(type -> registry.forType(type).isPresent())
.sorted()
.toList();
assertTrue(both.isEmpty(),
"These types have an extracted provisioner, so their attribute-aware delete branch "
+ "is now unreachable. Move that logic into the provisioner's "
+ "delete(StackResource, String) override and remove the entry from "
+ "DELETE_NEEDS_STACK_RESOURCE: " + both);
}
/**
* Every attribute-aware type is one Floci actually provisions. A typo in the set
* ({@code AWS::Events::Rules}) would never match, sending the real type down the
* type/physicalId path where its delete silently no-ops and leaves the resource live.
*/
@Test
void everyAttributeAwareTypeIsAProvisionedType() {
List<String> unknown = CloudFormationResourceProvisioner.DELETE_NEEDS_STACK_RESOURCE.stream()
.filter(type -> registry.forType(type).isEmpty())
.filter(type -> !CloudFormationResourceProvisioner.LEGACY_SWITCH_TYPES.contains(type))
.sorted()
.toList();
assertTrue(unknown.isEmpty(),
"DELETE_NEEDS_STACK_RESOURCE names types that nothing provisions, so the entry is "
+ "dead and the real type (if misspelled here) deletes by physical id alone: "
+ unknown);
}
}
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.services.appsync.AppSyncService;
import io.github.hectorvent.floci.services.autoscaling.AutoScalingService;
import io.github.hectorvent.floci.services.batch.BatchService;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnDynamicReferences;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CloudFrontCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.ConfigCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.DynamoDbCfnProvisioner;
@@ -132,7 +133,7 @@ import java.util.Arrays;
import java.util.List;
/**
* Builds {@link CloudFormationResourceProvisioner} for tests without a wall of positional nulls.
* Builds {@link CfnResourceDispatcher} for tests without a wall of positional nulls.
*
* <p>The provisioner takes one constructor argument per service it still provisions, so every test
* that built it directly had to pass 30-plus {@code null}s in the right order, and every argument
@@ -704,12 +705,12 @@ final class CfnProvisionerFixture {
: new CloudFormationResourceRegistry(inferredProvisioners());
}
public CloudFormationResourceProvisioner build() {
public CfnResourceDispatcher build() {
if (!registryChosenByTest) {
resourceRegistry = buildRegistry();
}
ensureDynamicReferences();
return new CloudFormationResourceProvisioner(
return new CfnResourceDispatcher(
objectMapper,
resourceRegistry,
dynamicReferences,
@@ -24,11 +24,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Pins the full set of CloudFormation resource types Floci provisions, and who serves each one.
*
* <p>This is the guard for the per-service provisioner migration. {@code provision}'s default arm
* <p>This is the guard against a type quietly losing its provisioner. {@code CfnResourceDispatcher}
* stubs an unknown type with {@code arn:aws:stub:::<logicalId>} and reports CREATE_COMPLETE, so a
* type that falls out of both the switch and the registry would otherwise pass every test while
* provisioning nothing. Making the inventory a checked-in file turns each migration slice into an
* intentional two-line diff.
* type that falls out of the registry would otherwise pass every test while provisioning nothing.
* Making the inventory a checked-in file turns each ownership change into an intentional diff.
*
* <p>Runs under {@code @QuarkusTest} deliberately: the registry is compared as CDI resolved it, so
* a provisioner written without {@code @ApplicationScoped} is caught. That mistake leaves the
@@ -40,7 +39,6 @@ class CfnResourceInventoryTest {
private static final Path INVENTORY =
Path.of("src/test/resources/cloudformation/supported-resource-types.tsv");
private static final Path SCHEMA_DIR = Path.of("local/aws/cfn-resource-schemas/us-east-1");
private static final String LEGACY_OWNER = "LEGACY_SWITCH";
/**
* Types with no CloudFormation registry schema. {@code AWS::CDK::Metadata} is emitted by the
@@ -52,32 +50,17 @@ class CfnResourceInventoryTest {
CloudFormationResourceRegistry registry;
@Test
void inventoryMatchesTheRegistryAndTheLegacySwitch() {
void inventoryMatchesTheRegistry() {
Map<String, String> actual = new TreeMap<>();
for (String type : registry.registeredTypes()) {
actual.put(type, registry.ownerOf(type));
}
for (String type : CloudFormationResourceProvisioner.LEGACY_SWITCH_TYPES) {
actual.put(type, LEGACY_OWNER);
}
assertEquals(render(readInventory()), render(actual),
"The provisioned resource-type inventory changed. If that was intentional, write "
+ "this exact content to " + INVENTORY + ".");
}
@Test
void noTypeIsServedByBothTheRegistryAndTheSwitch() {
List<String> both = registry.registeredTypes().stream()
.filter(CloudFormationResourceProvisioner.LEGACY_SWITCH_TYPES::contains)
.sorted()
.toList();
assertTrue(both.isEmpty(),
"A type served by an extracted provisioner must have its switch arm removed; the "
+ "registry wins, leaving the arm as dead code that still looks live: " + both);
}
@Test
void inventoryFileIsSortedAndFreeOfDuplicates() {
List<String> types = readTypeColumn();
@@ -134,10 +134,6 @@ class CfnSchemaCoverageTest {
for (Map.Entry<String, String> entry : inventory().entrySet()) {
String type = entry.getKey();
String owner = entry.getValue();
if ("LEGACY_SWITCH".equals(owner)) {
// The switch is being dismantled type by type; its arms are audited as they move.
continue;
}
Set<String> declared = schemaReadOnlyAttributes(type);
ProvisionerScan scan = scans.get(owner);
Set<String> set = scan == null ? Set.of() : scan.attributesFor(type);
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import org.junit.jupiter.api.BeforeEach;
@@ -20,7 +21,7 @@ class CloudFormationDeleteIdempotencyTest {
private DynamoDbService dynamoDbService;
private LambdaService lambdaService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnRollback;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.model.Instance;
@@ -31,7 +32,7 @@ class CloudFormationEc2ProvisionerTest {
private final ObjectMapper mapper = new ObjectMapper();
private Ec2Service ec2Service;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnRollback;
import io.github.hectorvent.floci.services.cloudformation.provisioners.IamManagedPolicyCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.IamPolicyCfnProvisioner;
@@ -43,7 +44,7 @@ class CloudFormationIamAttachmentProvisionerTest {
private final ObjectMapper mapper = new ObjectMapper();
private IamService iamService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -404,7 +405,7 @@ class CloudFormationIamAttachmentProvisionerTest {
assertEquals("old-user", result.getAttributes().get("InlineUserTargets"));
assertEquals("old-group", result.getAttributes().get("InlineGroupTargets"));
assertEquals("true", result.getAttributes().get(
CloudFormationResourceProvisioner.UPDATE_ROLLBACK_RESTORED_ATTR));
CfnRollback.UPDATE_ROLLBACK_RESTORED_ATTR));
verify(iamService).deleteRolePolicy("new-role", policyName);
verify(iamService, never()).deleteRolePolicy("old-role", policyName);
}
@@ -8441,7 +8441,7 @@ class CloudFormationIntegrationTest {
@Test
void createStack_samFunctionWithPackageTypeImageDeploysAsImageFunction() {
// Without PackageType carried through by the SAM transform, CloudFormationResourceProvisioner
// Without PackageType carried through by the SAM transform, the Lambda provisioner
// defaults PackageType to "Zip" (buildLambdaDesiredState's resolveOrDefault), which then also
// forces Runtime/Handler defaults onto a function that declared neither — the function is
// created as a broken Zip function instead of running the real container image.
@@ -8495,7 +8495,7 @@ class CloudFormationIntegrationTest {
@Test
void createStack_samFunctionWithImageConfigDeploysWithOverrides() {
// ImageConfig must also be carried through the SAM transform to CloudFormationResourceProvisioner,
// ImageConfig must also be carried through the SAM transform to the Lambda provisioner,
// which already reads it (provisionLambda's putResolvedMapIfPresent(configRequest, props,
// "ImageConfig", ...)) — without the transform copying it, a PackageType: Image SAM function's
// EntryPoint/Command/WorkingDirectory override silently never reaches the deployed function.
@@ -8660,7 +8660,7 @@ class CloudFormationIntegrationTest {
void createStack_samHttpApiAuthorizerHonorsCustomIdentitySource() {
// SAM's Authorizers.<Name>.IdentitySource lets a JWT authorizer read the token from
// somewhere other than the default Authorization header — e.g. a query-string token,
// the same case CloudFormationResourceProvisioner/ApiGatewayExecuteController already
// the same case the API Gateway provisioner/ApiGatewayExecuteController already
// support end-to-end for raw (non-SAM) templates. The SAM transform must forward it
// rather than always emitting the header default.
String template = """
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -39,7 +40,7 @@ class CloudFormationLambdaHotReloadCodeTest {
private final ObjectMapper mapper = new ObjectMapper();
private S3Service s3Service;
private LambdaService lambdaService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaCfnProvisioner;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
@@ -39,7 +40,7 @@ class CloudFormationLambdaLegacyNameModeTest {
private final ObjectMapper mapper = new ObjectMapper();
private LambdaService lambdaService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -43,7 +44,7 @@ class CloudFormationLambdaS3CodeProbeTest {
private final ObjectMapper mapper = new ObjectMapper();
private S3Service s3Service;
private LambdaService lambdaService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -34,7 +35,7 @@ class CloudFormationLogGroupProvisionerTest {
private final ObjectMapper mapper = new ObjectMapper();
private CloudWatchLogsService logsService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.ChangeSet;
import io.github.hectorvent.floci.services.cloudformation.model.Stack;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.quarkus.arc.ClientProxy;
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTest;
@@ -35,11 +36,10 @@ import static org.mockito.Mockito.withSettings;
* provisioning, then checks that the execution it rejects leaves its stack and change set as
* they were.
*
* <p>The provisioner bean is swapped for a mock whose default answer blocks {@code provision}
* for this test's stacks and forwards everything else to the real provisioner. The answer
* recognises those calls by method name and stack name rather than by stubbing one overload,
* because the service picks whichever {@code provision} overload the current main branch has,
* and a stubbing tied to an older overload silently returns null once main adds a new one.
* <p>The dispatcher bean is swapped for a mock whose default answer blocks {@code provision}
* for this test's stacks and forwards everything else to the real dispatcher. The answer
* recognises those calls by method name and stack name rather than by stubbing one overload, so
* it does not depend on which {@code provision} overload the service calls.
*/
@QuarkusTest
class CloudFormationServiceRestoreIntegrationTest {
@@ -57,20 +57,20 @@ class CloudFormationServiceRestoreIntegrationTest {
CloudFormationService service;
@Inject
CloudFormationResourceProvisioner provisioner;
CfnResourceDispatcher provisioner;
private final CountDownLatch activeOperations = new CountDownLatch(ACTIVE_OPERATIONS);
private final CountDownLatch releaseOperations = new CountDownLatch(1);
private CloudFormationResourceProvisioner blockingProvisioner;
private CfnResourceDispatcher blockingProvisioner;
@BeforeEach
void blockProvisioningForTestStacks() {
Answer<Object> realProvisioner = AdditionalAnswers.delegatesTo(ClientProxy.unwrap(provisioner));
blockingProvisioner = Mockito.mock(CloudFormationResourceProvisioner.class,
blockingProvisioner = Mockito.mock(CfnResourceDispatcher.class,
withSettings().defaultAnswer(invocation -> isTestStackProvision(invocation)
? provisionAfterRelease(invocation)
: realProvisioner.answer(invocation)));
QuarkusMock.installMockForType(blockingProvisioner, CloudFormationResourceProvisioner.class);
QuarkusMock.installMockForType(blockingProvisioner, CfnResourceDispatcher.class);
}
@Test
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.cloudformation.model.Stack;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnDynamicReferences;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.ssm.SsmService;
import org.junit.jupiter.api.BeforeEach;
@@ -35,12 +36,12 @@ class CloudFormationServiceRollbackTest {
private static final String ACCOUNT = "000000000000";
private static final String REGION = "us-east-1";
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
private CloudFormationService service;
@BeforeEach
void setUp() {
provisioner = mock(CloudFormationResourceProvisioner.class);
provisioner = mock(CfnResourceDispatcher.class);
EmulatorConfig config = mock(EmulatorConfig.class);
when(config.defaultAccountId()).thenReturn(ACCOUNT);
@@ -167,7 +167,7 @@ class CloudFormationStepFunctionsCleanupIntegrationTest {
void updateAfterStubUpgradeProvisionsTheRealStateMachine() {
// A stack that was created by a floci build that did not yet expand
// AWS::Serverless::StateMachine had this resource stubbed with a non-ARN physical id
// (<logicalId>-<8 hex>, see CloudFormationResourceProvisioner's default provisioning arm).
// (<logicalId>-<8 hex>, see CfnResourceDispatcher's stub arm).
// Its next update must provision the real state machine instead of failing with InvalidArn
// when findStateMachine tries to describe that non-ARN value.
String suffix = Long.toString(System.nanoTime(), 36);
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -56,7 +57,7 @@ class CloudFormationUnsupportedResourceTypeTest {
+ "MyThing-11a79dff is not removed here.";
private final ObjectMapper mapper = new ObjectMapper();
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -114,8 +115,8 @@ class CloudFormationUnsupportedResourceTypeTest {
@Test
void deleteOfUnsupportedTypeDoesNotThrow() {
// The same arm catches a type no provisioner ever created and a type the create switch does
// provision and this switch does not remove, so the line says what it leaves behind rather
// The same path catches a type no provisioner ever created and one that was only stubbed,
// neither of which left anything behind, so the line says what it leaves behind rather
// than claiming nothing was created.
List<LogRecord> logged = new CopyOnWriteArrayList<>();
@@ -130,7 +131,7 @@ class CloudFormationUnsupportedResourceTypeTest {
"expected the skipped delete to be reported at warn, got: " + rendered(logged));
}
private CloudFormationResourceProvisioner provisionerWithStubAllowed(boolean allowed) {
private CfnResourceDispatcher provisionerWithStubAllowed(boolean allowed) {
EmulatorConfig config = mock(EmulatorConfig.class);
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
EmulatorConfig.CloudFormationServiceConfig cloudformation =
@@ -150,7 +151,7 @@ class CloudFormationUnsupportedResourceTypeTest {
private <T> T whileCapturingProvisionerLogs(List<LogRecord> collected,
java.util.function.Supplier<T> action) {
java.util.logging.Logger logger =
java.util.logging.Logger.getLogger(CloudFormationResourceProvisioner.class.getName());
java.util.logging.Logger.getLogger(CfnResourceDispatcher.class.getName());
Level original = logger.getLevel();
Handler handler = new Handler() {
@Override
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.docker.ContainerReachableEndpoint;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
@@ -42,7 +43,7 @@ class CustomResourceProviderFrameworkTest {
private LambdaService lambdaService;
private ProviderFrameworkDetector detector;
private CustomResourceResponseStore store;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.docker.ContainerReachableEndpoint;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.lambda.LambdaService;
import io.github.hectorvent.floci.services.lambda.model.InvocationType;
import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
@@ -37,7 +38,7 @@ class CustomResourceProvisionerTest {
private final ObjectMapper mapper = new ObjectMapper();
private LambdaService lambdaService;
private CustomResourceResponseStore store;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -25,7 +26,7 @@ class DynamoDbReplicaCfnProvisionerTest {
private final ObjectMapper mapper = new ObjectMapper();
private DynamoDbService dynamoDbService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
import org.junit.jupiter.api.BeforeEach;
@@ -42,7 +43,7 @@ class DynamoDbStreamSpecificationCfnProvisionerTest {
private final ObjectMapper mapper = new ObjectMapper();
private DynamoDbService dynamoDbService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
import io.github.hectorvent.floci.services.eventbridge.model.EventBus;
import org.junit.jupiter.api.BeforeEach;
@@ -30,7 +31,7 @@ class EventBusDeleteOwnershipTest {
private static final String CREATED_TIME_ATTR = "FlociEventBusCreatedTime";
private EventBridgeService eventBridgeService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
import io.github.hectorvent.floci.services.eventbridge.model.EventBus;
import org.junit.jupiter.api.BeforeEach;
@@ -44,7 +45,7 @@ class EventBusProvisionOwnershipTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private EventBridgeService eventBridgeService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.cloudformation.provisioners.UpdateCleanupResult;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.rds.RdsService;
@@ -66,7 +67,7 @@ class RdsCfnProvisionerTest {
private RdsService rdsService;
private SecretsManagerService secretsManagerService;
private SsmService ssmService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
private Function<String, String> importResolver;
private Map<String, Boolean> conditions;
@@ -122,7 +123,7 @@ class RdsCfnProvisionerTest {
*/
private StackResource provisionUpdate(String logicalId, String type, String json, String existingPhysicalId) {
return provisioner.provision(logicalId, type, props(json), engine(),
"us-east-1", "000000000000", "my-stack", existingPhysicalId);
"us-east-1", "000000000000", "my-stack", existingPhysicalId, Map.of());
}
@Test
@@ -1321,7 +1321,7 @@ class SamTransformIntegrationTest {
.extract().asString();
// AGENTS.md:289-291 asks for the exact Fn::GetAtt key set the provisioner publishes
// (CloudFormationResourceProvisioner.java:4231-4233): Arn, Name, StateMachineRevisionId.
// (StepFunctionsCfnProvisioner): Arn, Name, StateMachineRevisionId.
// Asserting only "not a stub ARN" (as red loop 2 did) would also pass on an empty Output.
String machineArn = stackOutputValue(describeStacks, "MachineArn");
assertThat(machineArn, startsWith("arn:aws:states:"));
@@ -250,7 +250,7 @@ class SamTransformProcessorTest {
@Test
void expandSamTemplate_functionWithPackageTypeImage() throws Exception {
// PackageType must be carried through to the expanded AWS::Lambda::Function: without it,
// CloudFormationResourceProvisioner.buildLambdaDesiredState defaults PackageType to "Zip"
// LambdaCfnProvisioner.buildLambdaDesiredState defaults PackageType to "Zip"
// (resolveOrDefault(props, "PackageType", engine, "Zip")), which then forces Runtime/Handler
// defaults (nodejs18.x / index.handler) onto a function that never had either — the function
// gets created as a Zip function running the wrong runtime instead of the real container image.
@@ -276,7 +276,7 @@ class SamTransformProcessorTest {
assertEquals("000000000000.dkr.ecr.us-east-1.localhost:4566/my-repo:latest",
lambdaProps.path("Code").path("ImageUri").asText());
// No Handler/Runtime were declared and none should be synthesized by the transform itself —
// CloudFormationResourceProvisioner is responsible for not defaulting them once it sees
// LambdaCfnProvisioner is responsible for not defaulting them once it sees
// PackageType: Image (verified separately in CloudFormationIntegrationTest).
assertTrue(lambdaProps.path("Handler").isMissingNode());
assertTrue(lambdaProps.path("Runtime").isMissingNode());
@@ -325,7 +325,7 @@ class SamTransformProcessorTest {
@Test
void expandSamTemplate_functionWithImageConfig() throws Exception {
// ImageConfig (EntryPoint/Command/WorkingDirectory overrides for a container-image
// function) must also be carried through: CloudFormationResourceProvisioner.provisionLambda
// function) must also be carried through: LambdaCfnProvisioner
// already reads it (putResolvedMapIfPresent(configRequest, props, "ImageConfig", ...)), but
// the SAM transform previously dropped it, silently losing any container entry-point/command
// override on a PackageType: Image SAM function.
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceDispatcher;
import io.github.hectorvent.floci.services.docdb.DocDbService;
import io.github.hectorvent.floci.services.docdb.model.DocDbCluster;
import io.github.hectorvent.floci.services.docdb.model.DocDbInstance;
@@ -54,7 +55,7 @@ class SecretTargetAttachmentCfnProvisionerTest {
private SecretsManagerService secretsManagerService;
private RdsService rdsService;
private DocDbService docDbService;
private CloudFormationResourceProvisioner provisioner;
private CfnResourceDispatcher provisioner;
@BeforeEach
void setUp() {
@@ -0,0 +1,119 @@
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.services.cloudformation.model.StackResource;
import org.junit.jupiter.api.Test;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* The dispatch itself: what reaches the owning provisioner and how Cloud Control's stack-less
* path is wired. The stub arm and strict mode are pinned by
* {@code CloudFormationUnsupportedResourceTypeTest}.
*/
class CfnResourceDispatcherTest {
private static final String TYPE = "AWS::Test::Thing";
private final ObjectMapper mapper = new ObjectMapper();
private final CloudFormationResourceRegistry registry = mock(CloudFormationResourceRegistry.class);
private final CfnDynamicReferences dynamicReferences = mock(CfnDynamicReferences.class);
private final CfnResourceDispatcher dispatcher =
new CfnResourceDispatcher(mapper, registry, dynamicReferences, null);
@Test
void provisionStandaloneResolvesDynamicReferencesThroughTheService() {
// Cloud Control desired state can carry {{resolve:...}}; the throwaway engine must reach
// the same resolver a stack's engine does.
when(dynamicReferences.resolveDynamicReferences("{{resolve:ssm:/p}}", "us-east-1", false))
.thenReturn("resolved");
AtomicReference<String> seen = new AtomicReference<>();
when(registry.forType(TYPE)).thenReturn(Optional.of(provisioner((resource, ctx) -> {
seen.set(ctx.engine().resolve(mapper.getNodeFactory().textNode("{{resolve:ssm:/p}}")));
resource.setPhysicalId("thing-1");
})));
StackResource resource = dispatcher.provisionStandalone(TYPE, mapper.createObjectNode(),
"us-east-1", "000000000000");
assertEquals("resolved", seen.get());
assertEquals("thing-1", resource.getPhysicalId());
assertEquals("CREATE_COMPLETE", resource.getStatus());
}
@Test
void provisionSeedsTheResourceAndTheContextWithThePriorIdentity() {
AtomicReference<ProvisionContext> seenContext = new AtomicReference<>();
AtomicReference<Map<String, String>> seenAttributes = new AtomicReference<>();
when(registry.forType(TYPE)).thenReturn(Optional.of(provisioner((resource, ctx) -> {
seenContext.set(ctx);
seenAttributes.set(Map.copyOf(resource.getAttributes()));
})));
StackResource resource = dispatcher.provision("Thing", TYPE, mapper.createObjectNode(), null,
"us-east-1", "000000000000", "my-stack", "thing-prior", Map.of("Arn", "arn-prior"));
assertEquals("thing-prior", seenContext.get().priorPhysicalId());
assertEquals("my-stack", seenContext.get().stackName());
assertEquals(Map.of("Arn", "arn-prior"), seenAttributes.get());
assertEquals("thing-prior", resource.getPhysicalId(), "an owner that sets nothing keeps the prior id");
assertEquals("CREATE_COMPLETE", resource.getStatus());
}
@Test
void deleteHandsTheOwnerTheWholeResource() {
CfnResourceProvisioner owner = mock(CfnResourceProvisioner.class);
when(registry.forType(TYPE)).thenReturn(Optional.of(owner));
StackResource resource = new StackResource();
resource.setResourceType(TYPE);
resource.setPhysicalId("thing-1");
dispatcher.delete(resource, "us-east-1");
verify(owner).delete(resource, "us-east-1");
verify(owner, never()).delete(anyString(), anyString(), anyString());
}
@Test
void deleteStandaloneCarriesTheRecordedAttributes() {
CfnResourceProvisioner owner = mock(CfnResourceProvisioner.class);
when(registry.forType(TYPE)).thenReturn(Optional.of(owner));
dispatcher.deleteStandalone(TYPE, "thing-1", "us-east-1", Map.of("Role", "r"));
verify(owner).delete(any(StackResource.class), anyString());
verify(owner).delete(org.mockito.ArgumentMatchers.argThat((StackResource r) ->
"thing-1".equals(r.getPhysicalId()) && "r".equals(r.getAttributes().get("Role"))), any());
}
private static CfnResourceProvisioner provisioner(Provision body) {
return new CfnResourceProvisioner() {
@Override
public Set<String> resourceTypes() {
return Set.of(TYPE);
}
@Override
public void provision(StackResource resource, JsonNode properties, ProvisionContext ctx) {
body.run(resource, ctx);
}
};
}
@FunctionalInterface
private interface Provision {
void run(StackResource resource, ProvisionContext ctx);
}
}
@@ -33,9 +33,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* The single-service CloudFormation provisioners extracted from
* {@code CloudFormationResourceProvisioner} together, since each is a handful of lines with one
* service call.
* The single-service CloudFormation provisioners extracted from the former CloudFormation
* monolith together, since each is a handful of lines with one service call.
*
* <p>Every case asserts the exact physical id and the exact {@code Fn::GetAtt} attribute keys.
* Asserting status alone would prove nothing: an unmapped type still reports CREATE_COMPLETE via