Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

refactor(cloudformation): move EKS types into EksCfnProvisioner (#3891)

Hector Venturaefd08b3a7710
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
index c4595c77d0..f8dd2d6504 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
@@ -12,9 +12,6 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnDynami
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.UpdateCleanupResult;
import io.github.hectorvent.floci.services.eventbridge.model.Target;
-import io.github.hectorvent.floci.services.eks.EksService;
-import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
-import io.github.hectorvent.floci.services.eks.model.Nodegroup;
import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.iam.model.IamRole;
import io.github.hectorvent.floci.services.lambda.LambdaService;
@@ -93,7 +90,6 @@ public class CloudFormationResourceProvisioner {
static final Set<String> DELETE_NEEDS_STACK_RESOURCE = Set.of(
"AWS::ApiGatewayV2::Authorizer",
"AWS::CloudFormation::CustomResource",
- "AWS::EKS::Nodegroup",
"AWS::IAM::ManagedPolicy",
"AWS::IAM::Policy");
@@ -112,8 +108,6 @@ public class CloudFormationResourceProvisioner {
"AWS::ApiGatewayV2::Route",
"AWS::ApiGatewayV2::Stage",
"AWS::CloudFormation::CustomResource",
- "AWS::EKS::Cluster",
- "AWS::EKS::Nodegroup",
"AWS::IAM::AccessKey",
"AWS::IAM::InstanceProfile",
"AWS::IAM::ManagedPolicy",
@@ -139,7 +133,6 @@ public class CloudFormationResourceProvisioner {
private final ObjectMapper objectMapper;
private final CustomResourceResponseStore customResourceResponseStore;
private final ContainerReachableEndpoint reachableEndpoint;
- private final EksService eksService;
// Item 15 decomposition: extracted per-service provisioners are consulted before the switch
// below. As types migrate, their switch cases and provisionXxx methods are removed here; the
// now-dead service deps above are cleared in the final cleanup once the switch is empty.
@@ -156,7 +149,6 @@ public class CloudFormationResourceProvisioner {
ObjectMapper objectMapper,
CustomResourceResponseStore customResourceResponseStore,
ContainerReachableEndpoint reachableEndpoint,
- EksService eksService,
CloudFormationResourceRegistry resourceRegistry,
CfnDynamicReferences dynamicReferences,
EmulatorConfig config) {
@@ -169,7 +161,6 @@ public class CloudFormationResourceProvisioner {
this.objectMapper = objectMapper;
this.customResourceResponseStore = customResourceResponseStore;
this.reachableEndpoint = reachableEndpoint;
- this.eksService = eksService;
this.resourceRegistry = resourceRegistry;
this.dynamicReferences = dynamicReferences;
}
@@ -239,8 +230,6 @@ public class CloudFormationResourceProvisioner {
case "AWS::ApiGatewayV2::Deployment" -> provisionApiGatewayV2Deployment(resource, properties, engine, region);
case "AWS::CloudFormation::CustomResource" ->
provisionCustomResource(resource, properties, engine, region, accountId, stackName);
- case "AWS::EKS::Cluster" -> provisionEksCluster(resource, properties, engine, stackName);
- case "AWS::EKS::Nodegroup" -> provisionEksNodegroup(resource, properties, engine, stackName);
default -> {
if (resourceType != null && resourceType.startsWith("Custom::")) {
provisionCustomResource(resource, properties, engine, region, accountId, stackName);
@@ -383,19 +372,6 @@ public class CloudFormationResourceProvisioner {
deleteCustomResource(resource, region);
return;
}
- // Nodegroup deletion needs both the cluster name (from a Fn::GetAtt attribute) and the
- // nodegroup name (the physical id), which the type/physicalId delete path can't provide.
- if ("AWS::EKS::Nodegroup".equals(resourceType)) {
- String clusterName = resource.getAttributes().get("ClusterName");
- if (clusterName != null && !clusterName.isBlank()) {
- try {
- eksService.deleteNodeGroup(clusterName, resource.getPhysicalId());
- } catch (Exception e) {
- LOG.debugv("Error deleting nodegroup {0}: {1}", resource.getPhysicalId(), e.getMessage());
- }
- }
- return;
- }
// Authorizer deletion needs the api id (a stored attribute, not the physical id, which is
// the authorizer id) — same shape as the Nodegroup case above. Without this, the generic
// type/physicalId delete path has no case for this type at all and silently no-ops,
@@ -453,7 +429,6 @@ public class CloudFormationResourceProvisioner {
// No bus context on the type/physicalId path (e.g. CREATE-rollback); targets the default bus.
case "AWS::ApiGatewayV2::Api" -> apiGatewayV2Service.deleteApi(region, physicalId);
case "AWS::Lambda::LayerVersion" -> deleteLambdaLayerVersion(physicalId, region);
- case "AWS::EKS::Cluster" -> eksService.deleteCluster(physicalId);
// Warn for the same reason the create path does: the delete reports success over a
// type nothing here removes, and at debug that is invisible at the default log level.
// The line names the physical id without claiming a resource survives it: this arm
@@ -523,50 +498,6 @@ public class CloudFormationResourceProvisioner {
// ── EKS ─────────────────────────────────────────────────────────────────────
- private void provisionEksCluster(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,
- String stackName) {
- String name = resolveOptional(props, "Name", engine);
- if (name == null || name.isBlank()) {
- name = generatePhysicalName(stackName, r.getLogicalId(), 100, false);
- }
- CreateClusterRequest request = new CreateClusterRequest();
- request.setName(name);
- request.setVersion(resolveOptional(props, "Version", engine));
- request.setRoleArn(resolveOptional(props, "RoleArn", engine));
- var cluster = eksService.createCluster(request);
- r.setPhysicalId(cluster.getName());
- r.getAttributes().put("Arn", cluster.getArn());
- if (cluster.getEndpoint() != null) {
- r.getAttributes().put("Endpoint", cluster.getEndpoint());
- }
- }
-
- private void provisionEksNodegroup(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,
- String stackName) {
- String clusterName = resolveOptional(props, "ClusterName", engine);
- Nodegroup request = new Nodegroup();
- String nodegroupName = resolveOptional(props, "NodegroupName", engine);
- if (nodegroupName == null || nodegroupName.isBlank()) {
- nodegroupName = generatePhysicalName(stackName, r.getLogicalId(), 100, false);
- }
- request.setNodegroupName(nodegroupName);
- request.setNodeRole(resolveOptional(props, "NodeRole", engine));
- List<String> subnets = new ArrayList<>();
- if (props != null && props.has("Subnets") && props.get("Subnets").isArray()) {
- for (JsonNode subnet : props.get("Subnets")) {
- subnets.add(engine.resolve(subnet));
- }
- }
- request.setSubnets(subnets);
- var nodegroup = eksService.createNodeGroup(clusterName, request);
- r.setPhysicalId(nodegroup.getNodegroupName());
- r.getAttributes().put("ClusterName", nodegroup.getClusterName());
- r.getAttributes().put("NodegroupName", nodegroup.getNodegroupName());
- if (nodegroup.getNodegroupArn() != null) {
- r.getAttributes().put("Arn", nodegroup.getNodegroupArn());
- }
- }
-
// ── Lambda ────────────────────────────────────────────────────────────────
private void provisionLambda(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EksCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EksCfnProvisioner.java
new file mode 100644
index 0000000000..6dd99bf445
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EksCfnProvisioner.java
@@ -0,0 +1,115 @@
+package io.github.hectorvent.floci.services.cloudformation.provisioners;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
+import io.github.hectorvent.floci.services.eks.EksService;
+import io.github.hectorvent.floci.services.eks.model.Cluster;
+import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
+import io.github.hectorvent.floci.services.eks.model.Nodegroup;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.util.Set;
+
+/**
+ * CloudFormation provisioning for the EKS control-plane types. {@code AWS::EKS::Cluster} and
+ * {@code AWS::EKS::Nodegroup} share one provisioner over {@link EksService} because a nodegroup
+ * belongs to a cluster and its delete needs the cluster name, which is stored as a create-time
+ * attribute. {@code Ref} returns the cluster name for a Cluster and the nodegroup name for a
+ * Nodegroup, matching what the legacy switch published.
+ */
+@ApplicationScoped
+public class EksCfnProvisioner implements CfnResourceProvisioner {
+
+ private static final String CLUSTER = "AWS::EKS::Cluster";
+ private static final String NODEGROUP = "AWS::EKS::Nodegroup";
+
+ private final EksService eksService;
+
+ @Inject
+ public EksCfnProvisioner(EksService eksService) {
+ this.eksService = eksService;
+ }
+
+ @Override
+ public Set<String> resourceTypes() {
+ return Set.of(CLUSTER, NODEGROUP);
+ }
+
+ @Override
+ public void provision(StackResource r, JsonNode props, ProvisionContext ctx) {
+ switch (r.getResourceType()) {
+ case CLUSTER -> provisionCluster(r, props, ctx);
+ case NODEGROUP -> provisionNodegroup(r, props, ctx);
+ default -> throw new IllegalStateException("Unhandled type: " + r.getResourceType());
+ }
+ }
+
+ private void provisionCluster(StackResource r, JsonNode props, ProvisionContext ctx) {
+ String name = ctx.resolveOptional(props, "Name");
+ if (name == null || name.isBlank()) {
+ name = ctx.generatePhysicalName(r.getLogicalId(), 100, false);
+ }
+ CreateClusterRequest request = new CreateClusterRequest();
+ request.setName(name);
+ request.setVersion(ctx.resolveOptional(props, "Version"));
+ request.setRoleArn(ctx.resolveOptional(props, "RoleArn"));
+
+ Cluster cluster = eksService.createCluster(request);
+ r.setPhysicalId(cluster.getName());
+ r.getAttributes().put("Arn", cluster.getArn());
+ if (cluster.getEndpoint() != null) {
+ r.getAttributes().put("Endpoint", cluster.getEndpoint());
+ }
+ if (cluster.getCertificateAuthority() != null && cluster.getCertificateAuthority().getData() != null) {
+ r.getAttributes().put("CertificateAuthorityData", cluster.getCertificateAuthority().getData());
+ }
+ if (cluster.getIdentity() != null && cluster.getIdentity().getOidc() != null
+ && cluster.getIdentity().getOidc().getIssuer() != null) {
+ r.getAttributes().put("OpenIdConnectIssuerUrl", cluster.getIdentity().getOidc().getIssuer());
+ }
+ }
+
+ private void provisionNodegroup(StackResource r, JsonNode props, ProvisionContext ctx) {
+ String clusterName = ctx.resolveOptional(props, "ClusterName");
+ Nodegroup request = new Nodegroup();
+ String nodegroupName = ctx.resolveOptional(props, "NodegroupName");
+ if (nodegroupName == null || nodegroupName.isBlank()) {
+ nodegroupName = ctx.generatePhysicalName(r.getLogicalId(), 100, false);
+ }
+ request.setNodegroupName(nodegroupName);
+ request.setNodeRole(ctx.resolveOptional(props, "NodeRole"));
+ request.setSubnets(ctx.resolveStringList(props, "Subnets"));
+
+ Nodegroup nodegroup = eksService.createNodeGroup(clusterName, request);
+ r.setPhysicalId(nodegroup.getNodegroupName());
+ // ClusterName is stored so delete() can find the cluster, and NodegroupName mirrors the
+ // physical id; Arn is the schema's read-only attribute.
+ r.getAttributes().put("ClusterName", nodegroup.getClusterName());
+ r.getAttributes().put("NodegroupName", nodegroup.getNodegroupName());
+ if (nodegroup.getNodegroupArn() != null) {
+ r.getAttributes().put("Arn", nodegroup.getNodegroupArn());
+ }
+ }
+
+ @Override
+ public void delete(StackResource resource, String region) {
+ switch (resource.getResourceType()) {
+ case CLUSTER -> CfnDeletes.safeDelete("EKS cluster", resource.getPhysicalId(),
+ () -> eksService.deleteCluster(resource.getPhysicalId()), "ResourceNotFoundException");
+ case NODEGROUP -> {
+ // Deleting a nodegroup needs the cluster name (a create-time attribute) as well as
+ // the nodegroup name (the physical id), which the id-only delete path cannot supply.
+ String clusterName = resource.getAttributes().get("ClusterName");
+ if (clusterName != null && !clusterName.isBlank()) {
+ CfnDeletes.safeDelete("EKS nodegroup", resource.getPhysicalId(),
+ () -> eksService.deleteNodeGroup(clusterName, resource.getPhysicalId()),
+ "ResourceNotFoundException");
+ }
+ }
+ default -> {
+ // No other type reaches this provisioner's delete.
+ }
+ }
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java
index be2d979424..592b75b7ff 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java
@@ -55,6 +55,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.Ec2VpcCfn
import io.github.hectorvent.floci.services.cloudformation.provisioners.Ec2VpcEndpointCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.Ec2VpcGatewayAttachmentCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.EcrCfnProvisioner;
+import io.github.hectorvent.floci.services.cloudformation.provisioners.EksCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.EcsCapacityCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.EcsCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.ElbV2CfnProvisioner;
@@ -291,6 +292,9 @@ final class CfnProvisionerFixture {
discovered.add(new IamRoleCfnProvisioner(iamService));
discovered.add(new IamUserCfnProvisioner(iamService));
}
+ if (eksService != null) {
+ discovered.add(new EksCfnProvisioner(eksService));
+ }
if (elbV2Service != null) {
discovered.add(new ElbV2CfnProvisioner(elbV2Service));
}
@@ -691,7 +695,6 @@ final class CfnProvisionerFixture {
objectMapper,
customResourceResponseStore,
reachableEndpoint,
- eksService,
resourceRegistry,
dynamicReferences,
config);
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEksIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEksIntegrationTest.java
index caf4b7fea7..d3809910a2 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEksIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEksIntegrationTest.java
@@ -46,7 +46,8 @@ class CloudFormationEksIntegrationTest {
}
},
"Outputs": {
- "ClusterRef": {"Value": {"Ref": "Cluster"}}
+ "ClusterRef": {"Value": {"Ref": "Cluster"}},
+ "ClusterArn": {"Value": {"Fn::GetAtt": ["Cluster", "Arn"]}}
}
}
""".formatted(clusterName, nodegroupName);
@@ -72,7 +73,9 @@ class CloudFormationEksIntegrationTest {
.then()
.statusCode(200)
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))
- .body(containsString(clusterName));
+ .body(containsString(clusterName))
+ // Fn::GetAtt Cluster.Arn resolves to a real EKS arn, not the literal "Cluster.Arn".
+ .body(containsString("arn:aws:eks:"));
// The cluster really exists in EKS (provisioned, not stubbed).
given()
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EksCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EksCfnProvisionerTest.java
new file mode 100644
index 0000000000..aef6481aa2
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EksCfnProvisionerTest.java
@@ -0,0 +1,191 @@
+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.AwsException;
+import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
+import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
+import io.github.hectorvent.floci.services.eks.EksService;
+import io.github.hectorvent.floci.services.eks.model.CertificateAuthority;
+import io.github.hectorvent.floci.services.eks.model.Cluster;
+import io.github.hectorvent.floci.services.eks.model.ClusterIdentity;
+import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
+import io.github.hectorvent.floci.services.eks.model.Nodegroup;
+import io.github.hectorvent.floci.services.eks.model.OidcIdentity;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
+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 EKS control-plane types in isolation: the physical id (Ref) and Fn::GetAtt keys each
+ * publishes, the cluster name flowing into a nodegroup delete, and the already-gone tolerance.
+ */
+class EksCfnProvisionerTest {
+
+ private final EksService eks = mock(EksService.class);
+ private final EksCfnProvisioner provisioner = new EksCfnProvisioner(eks);
+ private final ObjectMapper mapper = new ObjectMapper();
+
+ @Test
+ void clusterRefIsItsNameAndItPublishesTheResolvableReadOnlyAttributes() throws Exception {
+ Cluster created = new Cluster();
+ created.setName("prod");
+ created.setArn("arn:aws:eks:us-east-1:000000000000:cluster/prod");
+ created.setEndpoint("https://prod.eks.amazonaws.com");
+ created.setCertificateAuthority(new CertificateAuthority("LS0tLS1CRUdJTg=="));
+ ClusterIdentity identity = new ClusterIdentity();
+ identity.setOidc(new OidcIdentity("https://oidc.eks.us-east-1.amazonaws.com/id/ABC"));
+ created.setIdentity(identity);
+ when(eks.createCluster(any(CreateClusterRequest.class))).thenReturn(created);
+
+ StackResource r = resource("AWS::EKS::Cluster", "Control");
+ provisioner.provision(r, props("""
+ {"Name": "prod", "RoleArn": "arn:aws:iam::000000000000:role/eks", "Version": "1.31"}
+ """), ctx());
+
+ assertEquals("prod", r.getPhysicalId());
+ assertEquals(Set.of("Arn", "Endpoint", "CertificateAuthorityData", "OpenIdConnectIssuerUrl"),
+ r.getAttributes().keySet());
+ assertEquals("arn:aws:eks:us-east-1:000000000000:cluster/prod", r.getAttributes().get("Arn"));
+ assertEquals("LS0tLS1CRUdJTg==", r.getAttributes().get("CertificateAuthorityData"));
+ assertEquals("https://oidc.eks.us-east-1.amazonaws.com/id/ABC",
+ r.getAttributes().get("OpenIdConnectIssuerUrl"));
+ }
+
+ @Test
+ void absentClusterNameIsGeneratedFromStackAndLogicalId() throws Exception {
+ Cluster created = new Cluster();
+ created.setName("my-stack-Control-abc123");
+ created.setArn("arn:aws:eks:us-east-1:000000000000:cluster/generated");
+ when(eks.createCluster(any(CreateClusterRequest.class))).thenReturn(created);
+
+ StackResource r = resource("AWS::EKS::Cluster", "Control");
+ provisioner.provision(r, props("{}"), ctx());
+
+ ArgumentCaptor<CreateClusterRequest> request = ArgumentCaptor.forClass(CreateClusterRequest.class);
+ verify(eks).createCluster(request.capture());
+ assertTrue(request.getValue().getName().matches("my-stack-Control-[0-9a-f]{12}"),
+ request.getValue().getName());
+ }
+
+ @Test
+ void nodegroupRefIsItsNameAndItStoresTheClusterNameForDelete() throws Exception {
+ Nodegroup created = new Nodegroup();
+ created.setNodegroupName("workers");
+ created.setClusterName("prod");
+ created.setNodegroupArn("arn:aws:eks:us-east-1:000000000000:nodegroup/prod/workers/uuid");
+ when(eks.createNodeGroup(eq("prod"), any(Nodegroup.class))).thenReturn(created);
+
+ StackResource r = resource("AWS::EKS::Nodegroup", "Workers");
+ provisioner.provision(r, props("""
+ {"ClusterName": "prod", "NodegroupName": "workers",
+ "NodeRole": "arn:aws:iam::000000000000:role/nodes", "Subnets": ["subnet-1", "subnet-2"]}
+ """), ctx());
+
+ assertEquals("workers", r.getPhysicalId());
+ assertEquals("prod", r.getAttributes().get("ClusterName"));
+ assertEquals("arn:aws:eks:us-east-1:000000000000:nodegroup/prod/workers/uuid",
+ r.getAttributes().get("Arn"));
+ ArgumentCaptor<Nodegroup> request = ArgumentCaptor.forClass(Nodegroup.class);
+ verify(eks).createNodeGroup(eq("prod"), request.capture());
+ assertEquals(List.of("subnet-1", "subnet-2"), request.getValue().getSubnets());
+ }
+
+ @Test
+ void deleteRemovesTheClusterByPhysicalId() {
+ StackResource r = resource("AWS::EKS::Cluster", "Control");
+ r.setPhysicalId("prod");
+
+ provisioner.delete(r, "us-east-1");
+
+ verify(eks).deleteCluster("prod");
+ }
+
+ @Test
+ void deleteRemovesTheNodegroupUsingTheStoredClusterName() {
+ StackResource r = resource("AWS::EKS::Nodegroup", "Workers");
+ r.setPhysicalId("workers");
+ r.getAttributes().put("ClusterName", "prod");
+
+ provisioner.delete(r, "us-east-1");
+
+ verify(eks).deleteNodeGroup("prod", "workers");
+ }
+
+ @Test
+ void deleteToleratesAClusterAlreadyGone() {
+ StackResource r = resource("AWS::EKS::Cluster", "Control");
+ r.setPhysicalId("prod");
+ doThrow(new AwsException("ResourceNotFoundException", "gone", 404))
+ .when(eks).deleteCluster("prod");
+
+ assertDoesNotThrow(() -> provisioner.delete(r, "us-east-1"));
+ }
+
+ @Test
+ void deletePropagatesAnUnexpectedClusterError() {
+ StackResource r = resource("AWS::EKS::Cluster", "Control");
+ r.setPhysicalId("prod");
+ doThrow(new AwsException("ResourceInUseException", "in use", 409))
+ .when(eks).deleteCluster("prod");
+
+ AwsException failure = assertThrows(AwsException.class, () -> provisioner.delete(r, "us-east-1"));
+ assertEquals("ResourceInUseException", failure.getErrorCode());
+ }
+
+ @Test
+ void deleteSkipsANodegroupWithNoStoredClusterName() {
+ StackResource r = resource("AWS::EKS::Nodegroup", "Workers");
+ r.setPhysicalId("workers");
+
+ provisioner.delete(r, "us-east-1");
+
+ verify(eks, never()).deleteNodeGroup(any(), any());
+ }
+
+ private ProvisionContext ctx() {
+ CloudFormationTemplateEngine engine = mock(CloudFormationTemplateEngine.class);
+ when(engine.resolve(any())).thenAnswer(inv -> {
+ JsonNode node = inv.getArgument(0);
+ return node == null ? null : node.asText();
+ });
+ when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));
+ when(engine.resolveStringList(any())).thenAnswer(inv -> {
+ JsonNode node = inv.getArgument(0);
+ List<String> out = new ArrayList<>();
+ if (node != null && node.isArray()) {
+ node.forEach(element -> out.add(element.asText()));
+ }
+ return out;
+ });
+ return new ProvisionContext(engine, "us-east-1", "000000000000", "my-stack");
+ }
+
+ private JsonNode props(String json) throws Exception {
+ return mapper.readTree(json);
+ }
+
+ private static StackResource resource(String type, String logicalId) {
+ StackResource r = new StackResource();
+ r.setLogicalId(logicalId);
+ r.setResourceType(type);
+ r.setAttributes(new HashMap<>());
+ return r;
+ }
+}
diff --git a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv
index 60156be47c..4d5428b8fe 100644
--- a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv
+++ b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv
@@ -51,3 +51,7 @@ AWS::Redshift::Cluster DeferMaintenanceIdentifier Floci does not emulate deferre
AWS::Route53::RecordSet Id schema gives no description; Ref returns the record name and the legacy spec gives the type no attributes
AWS::SQS::QueuePolicy Id schema gives no description; the policy has no backing entity to take an id from
AWS::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 move
+AWS::EKS::Cluster ClusterSecurityGroupId not modeled: Floci does not create a cluster security group, so there is no id to publish
+AWS::EKS::Cluster EncryptionConfigKeyArn not modeled: Floci does not apply envelope encryption, so no KMS key arn is resolved
+AWS::EKS::Cluster Id not modeled: Floci identifies a cluster by its Name (the primary identifier and Ref), not a separate Id
+AWS::EKS::Nodegroup Id not published: Floci identifies a nodegroup by its name within the cluster, which is the Ref, not the composite Id
diff --git a/src/test/resources/cloudformation/supported-resource-types.tsv b/src/test/resources/cloudformation/supported-resource-types.tsv
index ed8250c0fb..b0c3afad62 100644
--- a/src/test/resources/cloudformation/supported-resource-types.tsv
+++ b/src/test/resources/cloudformation/supported-resource-types.tsv
@@ -77,8 +77,8 @@ AWS::ECS::Cluster EcsCfnProvisioner
AWS::ECS::ClusterCapacityProviderAssociations EcsCapacityCfnProvisioner
AWS::ECS::Service EcsCfnProvisioner
AWS::ECS::TaskDefinition EcsCfnProvisioner
-AWS::EKS::Cluster LEGACY_SWITCH
-AWS::EKS::Nodegroup LEGACY_SWITCH
+AWS::EKS::Cluster EksCfnProvisioner
+AWS::EKS::Nodegroup EksCfnProvisioner
AWS::ElasticLoadBalancingV2::Listener ElbV2CfnProvisioner
AWS::ElasticLoadBalancingV2::ListenerRule ElbV2CfnProvisioner
AWS::ElasticLoadBalancingV2::LoadBalancer ElbV2CfnProvisioner