mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(cloudformation): provision AWS::StepFunctions::StateMachine (#1152)
CloudFormationResourceProvisioner previously had no case for
AWS::StepFunctions::StateMachine, so stacks containing one fell through
to the default branch that stubs a placeholder ARN and reports
CREATE_COMPLETE without invoking StepFunctionsService. Downstream
EventBridge Pipes that target the state machine then fail at runtime
with "State machine does not exist".
Add a provisioner that:
- Resolves StateMachineName (auto-generating from logical id when absent)
- Resolves DefinitionString and applies DefinitionSubstitutions
(the same ${Var} replacement CloudFormation performs server-side)
- Resolves RoleArn, StateMachineType, and Tags
- Delegates to the existing StepFunctionsService.createStateMachine
- Sets PhysicalId to the canonical ARN (matching AWS Ref semantics)
and exposes the Arn and Name attributes for Fn::GetAtt
Also wire deletion through StepFunctionsService.deleteStateMachine.
Adds an integration test that creates a stack with substitutions,
asserts the resolved definition is stored, asserts CFN outputs return
the canonical ARN and name, and asserts deletion removes the resource.
This commit is contained in:
1 parent
35f597addd
commit
a89121c625
2 files changed
+161
-1
No files matched your search
+59
-1
@@ -44,6 +44,8 @@ import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
import io.github.hectorvent.floci.services.sns.SnsService;
|
||||
import io.github.hectorvent.floci.services.sqs.SqsService;
|
||||
import io.github.hectorvent.floci.services.ssm.SsmService;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.StepFunctionsService;
|
||||
import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;
|
||||
import io.github.hectorvent.floci.services.apigateway.ApiGatewayService;
|
||||
import io.github.hectorvent.floci.services.apigatewayv2.ApiGatewayV2Service;
|
||||
import io.github.hectorvent.floci.services.apigatewayv2.model.*;
|
||||
@@ -98,6 +100,7 @@ public class CloudFormationResourceProvisioner {
|
||||
private final CognitoService cognitoService;
|
||||
private final EcsService ecsService;
|
||||
private final ElbV2Service elbV2Service;
|
||||
private final StepFunctionsService stepFunctionsService;
|
||||
|
||||
@Inject
|
||||
public CloudFormationResourceProvisioner(S3Service s3Service, SqsService sqsService,
|
||||
@@ -112,7 +115,8 @@ public class CloudFormationResourceProvisioner {
|
||||
PipesService pipesService,
|
||||
CognitoService cognitoService,
|
||||
EcsService ecsService,
|
||||
ElbV2Service elbV2Service) {
|
||||
ElbV2Service elbV2Service,
|
||||
StepFunctionsService stepFunctionsService) {
|
||||
this.s3Service = s3Service;
|
||||
this.sqsService = sqsService;
|
||||
this.snsService = snsService;
|
||||
@@ -130,6 +134,7 @@ public class CloudFormationResourceProvisioner {
|
||||
this.cognitoService = cognitoService;
|
||||
this.ecsService = ecsService;
|
||||
this.elbV2Service = elbV2Service;
|
||||
this.stepFunctionsService = stepFunctionsService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,6 +202,8 @@ public class CloudFormationResourceProvisioner {
|
||||
case "AWS::ApiGatewayV2::Stage" -> provisionApiGatewayV2Stage(resource, properties, engine, region);
|
||||
case "AWS::ApiGatewayV2::Deployment" -> provisionApiGatewayV2Deployment(resource, properties, engine, region);
|
||||
case "AWS::Pipes::Pipe" -> provisionPipe(resource, properties, engine, region, stackName);
|
||||
case "AWS::StepFunctions::StateMachine" ->
|
||||
provisionStepFunctionsStateMachine(resource, properties, engine, region, stackName);
|
||||
case "AWS::Lambda::EventSourceMapping" ->
|
||||
provisionLambdaEventSourceMapping(resource, properties, engine, region);
|
||||
case "AWS::Cognito::UserPool" ->
|
||||
@@ -253,6 +260,7 @@ public class CloudFormationResourceProvisioner {
|
||||
case "AWS::ECR::Repository" ->
|
||||
ecrService.deleteRepository(physicalId, null, true, region);
|
||||
case "AWS::Pipes::Pipe" -> pipesService.deletePipe(physicalId, region);
|
||||
case "AWS::StepFunctions::StateMachine" -> stepFunctionsService.deleteStateMachine(physicalId);
|
||||
case "AWS::Lambda::EventSourceMapping" -> lambdaService.deleteEventSourceMapping(physicalId);
|
||||
case "AWS::Cognito::UserPool" -> cognitoService.deleteUserPool(physicalId);
|
||||
case "AWS::Cognito::UserPoolClient" -> cognitoService.deleteUserPoolClient(physicalId);
|
||||
@@ -1358,6 +1366,56 @@ public class CloudFormationResourceProvisioner {
|
||||
r.getAttributes().put("Arn", pipe.getArn());
|
||||
}
|
||||
|
||||
private void provisionStepFunctionsStateMachine(StackResource r, JsonNode props,
|
||||
CloudFormationTemplateEngine engine,
|
||||
String region, String stackName) {
|
||||
String name = resolveOptional(props, "StateMachineName", engine);
|
||||
if (name == null || name.isBlank()) {
|
||||
name = generatePhysicalName(stackName, r.getLogicalId(), 80, false);
|
||||
}
|
||||
|
||||
String roleArn = resolveOptional(props, "RoleArn", engine);
|
||||
String type = resolveOptional(props, "StateMachineType", engine);
|
||||
Map<String, String> tags = parseCfnTags(props != null ? props.get("Tags") : null, engine);
|
||||
|
||||
String definition = resolveStateMachineDefinition(props, engine);
|
||||
|
||||
StateMachine sm = stepFunctionsService.createStateMachine(name, definition, roleArn, type, region, tags);
|
||||
|
||||
r.setPhysicalId(sm.getStateMachineArn());
|
||||
r.getAttributes().put("Arn", sm.getStateMachineArn());
|
||||
r.getAttributes().put("Name", sm.getName());
|
||||
}
|
||||
|
||||
private String resolveStateMachineDefinition(JsonNode props, CloudFormationTemplateEngine engine) {
|
||||
if (props == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String definition = resolveOptional(props, "DefinitionString", engine);
|
||||
if (definition == null && props.has("Definition") && !props.get("Definition").isNull()) {
|
||||
definition = engine.resolveNode(props.get("Definition")).toString();
|
||||
}
|
||||
if (definition == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JsonNode subsNode = props.get("DefinitionSubstitutions");
|
||||
if (subsNode == null || subsNode.isNull()) {
|
||||
return definition;
|
||||
}
|
||||
|
||||
JsonNode resolvedSubs = engine.resolveNode(subsNode);
|
||||
Iterator<Map.Entry<String, JsonNode>> entries = resolvedSubs.fields();
|
||||
while (entries.hasNext()) {
|
||||
Map.Entry<String, JsonNode> entry = entries.next();
|
||||
String placeholder = "${" + entry.getKey() + "}";
|
||||
String value = entry.getValue().isTextual() ? entry.getValue().asText() : entry.getValue().toString();
|
||||
definition = definition.replace(placeholder, value);
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private void provisionCdkMetadata(StackResource r) {
|
||||
|
||||
Reference in new issue
Block a user