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:
Luke Walker authored and GitHub committed 2026-06-09 00:42:54 -05:00
1 parent 35f597addd
commit a89121c625
2 files changed
+161 -1

No files matched your search

@@ -5635,6 +5635,108 @@ class CloudFormationIntegrationTest {
.statusCode(200);
}
private static final String SFN_CONTENT_TYPE = "application/x-amz-json-1.0";
@Test
void createStack_stepFunctionsStateMachineResolvesDefinitionSubstitutionsAndIsDeletable() {
String template = """
{
"Resources": {
"MyRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": "cfn-sfn-role",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "states.amazonaws.com" },
"Action": "sts:AssumeRole"
}]
}
}
},
"MyStateMachine": {
"Type": "AWS::StepFunctions::StateMachine",
"Properties": {
"StateMachineName": "cfn-sfn-pipeline",
"RoleArn": { "Fn::GetAtt": ["MyRole", "Arn"] },
"DefinitionString": "{\\"StartAt\\":\\"Done\\",\\"States\\":{\\"Done\\":{\\"Type\\":\\"Pass\\",\\"Result\\":\\"${Marker}\\",\\"End\\":true}}}",
"DefinitionSubstitutions": {
"Marker": "substituted-value"
},
"Tags": [
{ "Key": "env", "Value": "test" }
]
}
}
},
"Outputs": {
"StateMachineArn": { "Value": { "Ref": "MyStateMachine" } },
"StateMachineName": { "Value": { "Fn::GetAtt": ["MyStateMachine", "Name"] } }
}
}
""";
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateStack")
.formParam("StackName", "sfn-cfn-stack")
.formParam("TemplateBody", template)
.formParam("Capabilities.member.1", "CAPABILITY_NAMED_IAM")
.when()
.post("/")
.then()
.statusCode(200);
String expectedArn = "arn:aws:states:us-east-1:000000000000:stateMachine:cfn-sfn-pipeline";
given()
.header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine")
.contentType(SFN_CONTENT_TYPE)
.body("{\"stateMachineArn\":\"" + expectedArn + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("name", equalTo("cfn-sfn-pipeline"))
.body("roleArn", containsString("cfn-sfn-role"))
.body("definition", containsString("substituted-value"))
.body("definition", not(containsString("${Marker}")));
String describeXml = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
.formParam("StackName", "sfn-cfn-stack")
.when()
.post("/")
.then()
.statusCode(200)
.extract().asString();
assertThat(describeXml, containsString("<OutputKey>StateMachineArn</OutputKey>"));
assertThat(describeXml, containsString("<OutputValue>" + expectedArn + "</OutputValue>"));
assertThat(describeXml, containsString("<OutputKey>StateMachineName</OutputKey>"));
assertThat(describeXml, containsString("<OutputValue>cfn-sfn-pipeline</OutputValue>"));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteStack")
.formParam("StackName", "sfn-cfn-stack")
.when()
.post("/")
.then()
.statusCode(200);
given()
.header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine")
.contentType(SFN_CONTENT_TYPE)
.body("{\"stateMachineArn\":\"" + expectedArn + "\"}")
.when()
.post("/")
.then()
.body("__type", containsString("StateMachineDoesNotExist"));
}
// ── Issue #924: roll back failed stack creates (criterion #9) ────────────
@Test