mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(stepfunctions): add UpdateStateMachine and update in place on stack updates (#1867)
* feat(stepfunctions): add UpdateStateMachine and update in place on stack updates * test(dynamodb): retain Quarkus port for cleanup * chore: rerun CI after download outage * fix(cloudformation): preserve log group on failed rename * fix(cloudformation): scope update rollback to attempted resources * fix(cloudformation): delete resources after stack updates * test(cloudformation): wire cloudfront fixture dependency * fix: include Step Functions update date in describe response * fix: preserve Step Functions describe response shape * fix: preserve generated Step Functions names
This commit is contained in:
1 parent
da5ff910b4
commit
97ac3cabb5
15 files changed
+4569
-119
No files matched your search
+38
-2
@@ -220,6 +220,31 @@ class CloudFormationEventBusIntegrationTest {
|
||||
""".formatted(busName);
|
||||
}
|
||||
|
||||
private static String eventBusAndNamedRuleTemplate(String busName, String description) {
|
||||
return """
|
||||
{
|
||||
"Resources": {
|
||||
"Bus": {
|
||||
"Type": "AWS::Events::EventBus",
|
||||
"Properties": {
|
||||
"Name": "%s",
|
||||
"Description": "%s"
|
||||
}
|
||||
},
|
||||
"Rule": {
|
||||
"Type": "AWS::Events::Rule",
|
||||
"Properties": {
|
||||
"Name": "%s-rule",
|
||||
"EventBusName": { "Ref": "Bus" },
|
||||
"EventPattern": { "source": ["com.example.orders"] },
|
||||
"State": "ENABLED"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".formatted(busName, description, busName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customEventBusIsRegisteredSoRuleReferencingItSucceeds() throws InterruptedException {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
@@ -359,7 +384,7 @@ class CloudFormationEventBusIntegrationTest {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String busName = "update-bus-" + suffix;
|
||||
String stackName = "eventbus-update-" + suffix;
|
||||
String originalTemplate = eventBusOnlyTemplate(busName, "before");
|
||||
String originalTemplate = eventBusAndNamedRuleTemplate(busName, "before");
|
||||
|
||||
createStack(stackName, originalTemplate);
|
||||
assertStackStatus(stackName, "CREATE_COMPLETE");
|
||||
@@ -367,7 +392,7 @@ class CloudFormationEventBusIntegrationTest {
|
||||
updateStack(stackName, originalTemplate);
|
||||
assertStackStatus(stackName, "UPDATE_COMPLETE");
|
||||
|
||||
updateStack(stackName, eventBusOnlyTemplate(busName, "after"));
|
||||
updateStack(stackName, eventBusAndNamedRuleTemplate(busName, "after"));
|
||||
assertStackStatus(stackName, "UPDATE_ROLLBACK_COMPLETE");
|
||||
|
||||
given()
|
||||
@@ -388,6 +413,17 @@ class CloudFormationEventBusIntegrationTest {
|
||||
|
||||
deleteStack(stackName);
|
||||
awaitStackDeleted(stackName);
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("Authorization", EVENTS_AUTH)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeEventBus")
|
||||
.body("{\"Name\":\"" + busName + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1566
File diff suppressed because it is too large.
Load diff
+254
@@ -0,0 +1,254 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.github.hectorvent.floci.services.stepfunctions.StepFunctionsService;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.mockito.InjectSpy;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@QuarkusTest
|
||||
class CloudFormationStepFunctionsCleanupIntegrationTest {
|
||||
|
||||
private static final String SFN_CONTENT_TYPE = "application/x-amz-json-1.0";
|
||||
|
||||
@InjectSpy
|
||||
StepFunctionsService stepFunctionsService;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void permanentReplacementCleanupFailureKeepsCommittedUpdateAndWarns() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "sfn-cleanup-warning-" + suffix;
|
||||
String oldName = "sfn-cleanup-old-" + suffix;
|
||||
String newName = "sfn-cleanup-new-" + suffix;
|
||||
String exportName = "sfn-cleanup-export-" + suffix;
|
||||
String oldArn = stateMachineArn(oldName);
|
||||
String newArn = stateMachineArn(newName);
|
||||
|
||||
createStack(stackName, template(oldName, "old-definition", "old-output", exportName));
|
||||
|
||||
Mockito.doThrow(new IllegalStateException("simulated cleanup failure"))
|
||||
.when(stepFunctionsService)
|
||||
.deleteStateMachineIfRevisionMatches(eq(oldArn), anyString());
|
||||
|
||||
updateStack(stackName, template(newName, "new-definition", "new-output", exportName));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"))
|
||||
.body(containsString("<StackStatusReason>"))
|
||||
.body(containsString(oldArn))
|
||||
.body(containsString("<OutputValue>new-output</OutputValue>"))
|
||||
.body(not(containsString("<OutputValue>old-output</OutputValue>")));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListExports")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Name>" + exportName + "</Name>"))
|
||||
.body(containsString("<Value>new-output</Value>"))
|
||||
.body(not(containsString("<Value>old-output</Value>")));
|
||||
|
||||
assertStateMachine(oldArn, "old-definition");
|
||||
assertStateMachine(newArn, "new-definition");
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "GetTemplate")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString(newName))
|
||||
.body(not(containsString(oldName)));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStackEvents")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<PhysicalResourceId>" + oldArn + "</PhysicalResourceId>"))
|
||||
.body(containsString("<ResourceStatus>DELETE_IN_PROGRESS</ResourceStatus>"))
|
||||
.body(containsString("<ResourceStatus>DELETE_FAILED</ResourceStatus>"));
|
||||
|
||||
verify(stepFunctionsService, times(3))
|
||||
.deleteStateMachineIfRevisionMatches(eq(oldArn), anyString());
|
||||
|
||||
Mockito.doCallRealMethod()
|
||||
.when(stepFunctionsService)
|
||||
.deleteStateMachineIfRevisionMatches(eq(oldArn), anyString());
|
||||
deleteStack(stackName);
|
||||
stepFunctionsService.deleteStateMachine(oldArn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void transientReplacementCleanupFailureSucceedsOnThirdAttempt() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "sfn-cleanup-retry-" + suffix;
|
||||
String oldName = "sfn-cleanup-retry-old-" + suffix;
|
||||
String newName = "sfn-cleanup-retry-new-" + suffix;
|
||||
String exportName = "sfn-cleanup-retry-export-" + suffix;
|
||||
String oldArn = stateMachineArn(oldName);
|
||||
String newArn = stateMachineArn(newName);
|
||||
|
||||
createStack(stackName, template(oldName, "old-definition", "old-output", exportName));
|
||||
|
||||
Mockito.doThrow(new IllegalStateException("first cleanup failure"))
|
||||
.doThrow(new IllegalStateException("second cleanup failure"))
|
||||
.doCallRealMethod()
|
||||
.when(stepFunctionsService)
|
||||
.deleteStateMachineIfRevisionMatches(eq(oldArn), anyString());
|
||||
|
||||
updateStack(stackName, template(newName, "new-definition", "new-output", exportName));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"))
|
||||
.body(not(containsString("<StackStatusReason>")))
|
||||
.body(containsString("<OutputValue>new-output</OutputValue>"));
|
||||
|
||||
assertStateMachineMissing(oldArn);
|
||||
assertStateMachine(newArn, "new-definition");
|
||||
verify(stepFunctionsService, times(3))
|
||||
.deleteStateMachineIfRevisionMatches(eq(oldArn), anyString());
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStackEvents")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<PhysicalResourceId>" + oldArn + "</PhysicalResourceId>"))
|
||||
.body(containsString("<ResourceStatus>DELETE_IN_PROGRESS</ResourceStatus>"))
|
||||
.body(containsString("<ResourceStatus>DELETE_COMPLETE</ResourceStatus>"))
|
||||
.body(not(containsString("<ResourceStatus>DELETE_FAILED</ResourceStatus>")));
|
||||
|
||||
deleteStack(stackName);
|
||||
}
|
||||
|
||||
private static void createStack(String stackName, String templateBody) {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", templateBody)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static void updateStack(String stackName, String templateBody) {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", templateBody)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static void deleteStack(String stackName) {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteStack")
|
||||
.formParam("StackName", stackName)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static void assertStateMachine(String arn, String definitionMarker) {
|
||||
given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body("{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("definition", containsString(definitionMarker));
|
||||
}
|
||||
|
||||
private static void assertStateMachineMissing(String arn) {
|
||||
given()
|
||||
.header("X-Amz-Target", "AWSStepFunctions.DescribeStateMachine")
|
||||
.contentType(SFN_CONTENT_TYPE)
|
||||
.body("{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", containsString("StateMachineDoesNotExist"));
|
||||
}
|
||||
|
||||
private static String stateMachineArn(String name) {
|
||||
return "arn:aws:states:us-east-1:000000000000:stateMachine:" + name;
|
||||
}
|
||||
|
||||
private static String template(
|
||||
String stateMachineName,
|
||||
String definitionMarker,
|
||||
String outputValue,
|
||||
String exportName) {
|
||||
return """
|
||||
{
|
||||
"Resources": {
|
||||
"MyStateMachine": {
|
||||
"Type": "AWS::StepFunctions::StateMachine",
|
||||
"Properties": {
|
||||
"StateMachineName": "%s",
|
||||
"RoleArn": "arn:aws:iam::000000000000:role/cfn-sfn-cleanup-role",
|
||||
"DefinitionString": "{\\"StartAt\\":\\"Done\\",\\"States\\":{\\"Done\\":{\\"Type\\":\\"Pass\\",\\"Result\\":\\"%s\\",\\"End\\":true}}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"Marker": {
|
||||
"Value": "%s",
|
||||
"Export": {"Name": "%s"}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".formatted(
|
||||
stateMachineName, definitionMarker, outputValue, exportName);
|
||||
}
|
||||
}
|
||||
+354
@@ -0,0 +1,354 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* UpdateStateMachine — the AWS API action and the behavior CloudFormation relies on when a stack
|
||||
* update re-provisions an AWS::StepFunctions::StateMachine (previously Floci always called
|
||||
* CreateStateMachine, which failed with StateMachineAlreadyExists and rolled the stack update back).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class StepFunctionsUpdateStateMachineIntegrationTest {
|
||||
|
||||
private static final String CT = "application/x-amz-json-1.0";
|
||||
private static final String DEF = "{\\\"StartAt\\\":\\\"D\\\",\\\"States\\\":{\\\"D\\\":{\\\"Type\\\":\\\"Pass\\\",\\\"End\\\":true}}}";
|
||||
private static final String DEF2 = "{\\\"StartAt\\\":\\\"W\\\",\\\"States\\\":{\\\"W\\\":{\\\"Type\\\":\\\"Wait\\\",\\\"Seconds\\\":1,\\\"End\\\":true}}}";
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String target, String body) {
|
||||
return given().header("X-Amz-Target", "AWSStepFunctions." + target).contentType(CT).body(body).when().post("/");
|
||||
}
|
||||
|
||||
private static String createStateMachine(String name) {
|
||||
return call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r1\"}")
|
||||
.then().statusCode(200).extract().jsonPath().getString("stateMachineArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateChangesDefinitionAndRoleArn() {
|
||||
String arn = createStateMachine("upd-def-" + System.currentTimeMillis());
|
||||
|
||||
Response update = call("UpdateStateMachine",
|
||||
"{\"stateMachineArn\":\"" + arn + "\",\"definition\":\"" + DEF2 + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r2\"}")
|
||||
.then().statusCode(200)
|
||||
.body("updateDate", notNullValue())
|
||||
.body("revisionId", notNullValue())
|
||||
.extract().response();
|
||||
assertTrue(update.asString().contains("\"stateMachineVersionArn\":null"));
|
||||
|
||||
// The update is reflected in DescribeStateMachine.
|
||||
Response describe = call("DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("roleArn", is("arn:aws:iam::000000000000:role/r2"))
|
||||
.body("definition", containsString("\"Wait\""))
|
||||
.extract().response();
|
||||
assertFalse(describe.jsonPath().getMap("").containsKey("updateDate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void directUpdatePreservesExistingTags() {
|
||||
String name = "upd-tags-" + System.currentTimeMillis();
|
||||
String arn = call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r1\","
|
||||
+ "\"tags\":[{\"key\":\"owner\",\"value\":\"platform\"},"
|
||||
+ "{\"key\":\"stage\",\"value\":\"test\"}]}")
|
||||
.then().statusCode(200).extract().jsonPath().getString("stateMachineArn");
|
||||
|
||||
call("UpdateStateMachine",
|
||||
"{\"stateMachineArn\":\"" + arn + "\",\"definition\":\"" + DEF2 + "\"}")
|
||||
.then().statusCode(200);
|
||||
|
||||
call("ListTagsForResource", "{\"resourceArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("tags.size()", is(2))
|
||||
.body("tags.find { it.key == 'owner' }.value", is("platform"))
|
||||
.body("tags.find { it.key == 'stage' }.value", is("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateMissingStateMachineReturnsStateMachineDoesNotExist() {
|
||||
String missing = "arn:aws:states:us-east-1:000000000000:stateMachine:missing-" + System.currentTimeMillis();
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + missing + "\",\"definition\":\"" + DEF + "\"}")
|
||||
.then().statusCode(400).body(containsString("StateMachineDoesNotExist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWithoutDefinitionOrRoleArnReturnsMissingRequiredParameter() {
|
||||
String arn = createStateMachine("upd-empty-" + System.currentTimeMillis());
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(400).body(containsString("MissingRequiredParameter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWithPublishReturnsVersionArn() {
|
||||
String arn = createStateMachine("upd-pub-" + System.currentTimeMillis());
|
||||
Response published = call("UpdateStateMachine", """
|
||||
{
|
||||
"stateMachineArn":"%s",
|
||||
"definition":"%s",
|
||||
"roleArn":"arn:aws:iam::000000000000:role/r2",
|
||||
"loggingConfiguration":{
|
||||
"level":"ALL",
|
||||
"includeExecutionData":true,
|
||||
"destinations":[{
|
||||
"cloudWatchLogsLogGroup":{
|
||||
"logGroupArn":"arn:aws:logs:us-east-1:000000000000:log-group:version:*"
|
||||
}
|
||||
}]
|
||||
},
|
||||
"tracingConfiguration":{"enabled":true},
|
||||
"encryptionConfiguration":{
|
||||
"type":"CUSTOMER_MANAGED_KMS_KEY",
|
||||
"kmsKeyId":"alias/version-key",
|
||||
"kmsDataKeyReusePeriodSeconds":120
|
||||
},
|
||||
"publish":true,
|
||||
"versionDescription":"first update"
|
||||
}
|
||||
""".formatted(arn, DEF2));
|
||||
published.then().statusCode(200)
|
||||
.body("updateDate", notNullValue())
|
||||
.body("revisionId", notNullValue())
|
||||
.body("stateMachineVersionArn", containsString(arn + ":1"));
|
||||
String versionArn = published.jsonPath().getString("stateMachineVersionArn");
|
||||
String versionRevision = published.jsonPath().getString("revisionId");
|
||||
|
||||
call("UpdateStateMachine", """
|
||||
{
|
||||
"stateMachineArn":"%s",
|
||||
"definition":"%s",
|
||||
"roleArn":"arn:aws:iam::000000000000:role/r3",
|
||||
"loggingConfiguration":{
|
||||
"level":"OFF",
|
||||
"includeExecutionData":false,
|
||||
"destinations":[]
|
||||
},
|
||||
"tracingConfiguration":{"enabled":false},
|
||||
"encryptionConfiguration":{"type":"AWS_OWNED_KEY"}
|
||||
}
|
||||
""".formatted(arn, DEF))
|
||||
.then().statusCode(200);
|
||||
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + versionArn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineArn", is(versionArn))
|
||||
.body("creationDate", notNullValue())
|
||||
.body("definition", containsString("\"Wait\""))
|
||||
.body("roleArn", is("arn:aws:iam::000000000000:role/r2"))
|
||||
.body("revisionId", is(versionRevision))
|
||||
.body("description", is("first update"))
|
||||
.body("loggingConfiguration.level", is("ALL"))
|
||||
.body("loggingConfiguration.includeExecutionData", is(true))
|
||||
.body("tracingConfiguration.enabled", is(true))
|
||||
.body("encryptionConfiguration.type", is("CUSTOMER_MANAGED_KMS_KEY"))
|
||||
.body("encryptionConfiguration.kmsKeyId", is("alias/version-key"))
|
||||
.body("encryptionConfiguration.kmsDataKeyReusePeriodSeconds", is(120));
|
||||
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("definition", containsString("\"Pass\""))
|
||||
.body("roleArn", is("arn:aws:iam::000000000000:role/r3"))
|
||||
.body("loggingConfiguration.level", is("OFF"))
|
||||
.body("tracingConfiguration.enabled", is(false))
|
||||
.body("encryptionConfiguration.type", is("AWS_OWNED_KEY"));
|
||||
|
||||
call("DeleteStateMachineVersion",
|
||||
"{\"stateMachineVersionArn\":\"" + versionArn + "\"}")
|
||||
.then().statusCode(200);
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + versionArn + "\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("StateMachineDoesNotExist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateValidatesRequiredAndMalformedArns() {
|
||||
call("UpdateStateMachine", "{\"definition\":\"" + DEF2 + "\"}")
|
||||
.then().statusCode(400).body(containsString("MissingRequiredParameter"));
|
||||
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"\",\"definition\":\"" + DEF2 + "\"}")
|
||||
.then().statusCode(400).body(containsString("InvalidArn"));
|
||||
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"not-an-arn\",\"definition\":\""
|
||||
+ DEF2 + "\"}")
|
||||
.then().statusCode(400).body(containsString("InvalidArn"));
|
||||
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":42,\"definition\":\"" + DEF2 + "\"}")
|
||||
.then().statusCode(400).body(containsString("ValidationException"));
|
||||
|
||||
String distributedMapArn =
|
||||
"arn:aws:states:us-east-1:000000000000:stateMachine:machine/map-label";
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + distributedMapArn
|
||||
+ "\",\"definition\":\"" + DEF2 + "\"}")
|
||||
.then().statusCode(400).body(containsString("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectedInputsDoNotMutateTheStateMachine() {
|
||||
String arn = createStateMachine("upd-invalid-" + System.currentTimeMillis());
|
||||
String initialRevision = call(
|
||||
"DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200).extract().jsonPath().getString("revisionId");
|
||||
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn + "\",\"roleArn\":\"\"}")
|
||||
.then().statusCode(400).body(containsString("InvalidArn"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
|
||||
+ "\",\"roleArn\":\"arn:aws:s3:::not-a-role\"}")
|
||||
.then().statusCode(400).body(containsString("InvalidArn"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn + "\",\"definition\":\"\"}")
|
||||
.then().statusCode(400).body(containsString("InvalidDefinition"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
|
||||
+ "\",\"definition\":\"{}\"}")
|
||||
.then().statusCode(400).body(containsString("InvalidDefinition"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
|
||||
+ "\",\"definition\":\"{\\\"States\\\":{\\\"A\\\":{"
|
||||
+ "\\\"Type\\\":\\\"Pass\\\",\\\"End\\\":true}}}\"}")
|
||||
.then().statusCode(400).body(containsString("InvalidDefinition"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
|
||||
+ "\",\"definition\":\"{\\\"StartAt\\\":\\\"A\\\","
|
||||
+ "\\\"States\\\":{\\\"A\\\":{\\\"End\\\":true}}}\"}")
|
||||
.then().statusCode(400).body(containsString("InvalidDefinition"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn + "\",\"definition\":\""
|
||||
+ DEF2 + "\",\"loggingConfiguration\":{\"level\":\"TRACE\"}}")
|
||||
.then().statusCode(400).body(containsString("InvalidLoggingConfiguration"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn + "\",\"definition\":\""
|
||||
+ DEF2 + "\",\"tracingConfiguration\":{\"enabled\":\"yes\"}}")
|
||||
.then().statusCode(400).body(containsString("InvalidTracingConfiguration"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn + "\",\"definition\":\""
|
||||
+ DEF2
|
||||
+ "\",\"encryptionConfiguration\":{\"type\":\"CUSTOMER_MANAGED_KMS_KEY\"}}")
|
||||
.then().statusCode(400).body(containsString("InvalidEncryptionConfiguration"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn + "\",\"definition\":\""
|
||||
+ DEF2 + "\",\"versionDescription\":\"not published\"}")
|
||||
.then().statusCode(400).body(containsString("ValidationException"));
|
||||
|
||||
Response after = call(
|
||||
"DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}");
|
||||
after.then().statusCode(200)
|
||||
.body("definition", containsString("\"Pass\""))
|
||||
.body("roleArn", is("arn:aws:iam::000000000000:role/r1"));
|
||||
assertEquals(initialRevision, after.jsonPath().getString("revisionId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRotatesRevisionAndRoundTripsConfigurations() {
|
||||
String arn = createStateMachine("upd-config-" + System.currentTimeMillis());
|
||||
Response initial = call(
|
||||
"DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}");
|
||||
initial.then().statusCode(200)
|
||||
.body("loggingConfiguration.level", is("OFF"))
|
||||
.body("loggingConfiguration.includeExecutionData", is(false))
|
||||
.body("loggingConfiguration.destinations.size()", is(0))
|
||||
.body("tracingConfiguration.enabled", is(false))
|
||||
.body("encryptionConfiguration.type", is("AWS_OWNED_KEY"));
|
||||
String initialRevision = initial.jsonPath().getString("revisionId");
|
||||
|
||||
Response update = call("UpdateStateMachine", """
|
||||
{
|
||||
"stateMachineArn":"%s",
|
||||
"definition":"%s",
|
||||
"loggingConfiguration":{
|
||||
"level":"ALL",
|
||||
"includeExecutionData":true,
|
||||
"destinations":[{
|
||||
"cloudWatchLogsLogGroup":{
|
||||
"logGroupArn":"arn:aws:logs:us-east-1:000000000000:log-group:sfn:*"
|
||||
}
|
||||
}]
|
||||
},
|
||||
"tracingConfiguration":{"enabled":true},
|
||||
"encryptionConfiguration":{
|
||||
"type":"CUSTOMER_MANAGED_KMS_KEY",
|
||||
"kmsKeyId":"alias/sfn-key",
|
||||
"kmsDataKeyReusePeriodSeconds":120
|
||||
}
|
||||
}
|
||||
""".formatted(arn, DEF2));
|
||||
update.then().statusCode(200).body("revisionId", notNullValue());
|
||||
String updatedRevision = update.jsonPath().getString("revisionId");
|
||||
assertNotEquals(initialRevision, updatedRevision);
|
||||
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("revisionId", is(updatedRevision))
|
||||
.body("loggingConfiguration.level", is("ALL"))
|
||||
.body("loggingConfiguration.includeExecutionData", is(true))
|
||||
.body("tracingConfiguration.enabled", is(true))
|
||||
.body("encryptionConfiguration.type", is("CUSTOMER_MANAGED_KMS_KEY"))
|
||||
.body("encryptionConfiguration.kmsKeyId", is("alias/sfn-key"))
|
||||
.body("encryptionConfiguration.kmsDataKeyReusePeriodSeconds", is(120));
|
||||
|
||||
call("DescribeStateMachine",
|
||||
"{\"stateMachineArn\":\"" + arn + "\",\"includedData\":\"METADATA_ONLY\"}")
|
||||
.then().statusCode(200)
|
||||
.body("definition", is("{}"))
|
||||
.body("encryptionConfiguration.type", is("CUSTOMER_MANAGED_KMS_KEY"));
|
||||
|
||||
call("DescribeStateMachine",
|
||||
"{\"stateMachineArn\":\"" + arn + "\",\"includedData\":\"ALL_DATA\"}")
|
||||
.then().statusCode(200)
|
||||
.body("definition", containsString("\"Wait\""));
|
||||
|
||||
call("DescribeStateMachine",
|
||||
"{\"stateMachineArn\":\"" + arn + "\",\"includedData\":\"INVALID\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("ValidationException"));
|
||||
|
||||
call("DescribeStateMachine",
|
||||
"{\"stateMachineArn\":\"" + arn + "\",\"includedData\":42}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsUnsupportedStateMachineTypeBeforePersistence() {
|
||||
String name = "invalid-type-" + System.currentTimeMillis();
|
||||
call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r1\","
|
||||
+ "\"type\":\"BASIC\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("StateMachineTypeNotSupported"));
|
||||
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":"
|
||||
+ "\"arn:aws:states:us-east-1:000000000000:stateMachine:" + name + "\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("StateMachineDoesNotExist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeValidatesRequiredAndQualifiedArns() {
|
||||
call("DescribeStateMachine", "{}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("MissingRequiredParameter"));
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":42}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("ValidationException"));
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"not-an-arn\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("InvalidArn"));
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":"
|
||||
+ "\"arn:aws:states:us-east-1:000000000000:"
|
||||
+ "stateMachine:machine/map-label\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("ValidationException"));
|
||||
}
|
||||
}
|
||||
+147
-11
@@ -11,6 +11,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.emptyOrNullString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* State machine version APIs — the Terraform AWS provider calls ListStateMachineVersions after
|
||||
@@ -58,19 +59,25 @@ class StepFunctionsVersionsIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listVersionsAreReturnedNewestFirst() {
|
||||
void publishIsIdempotentPerRevisionAndVersionsAreReturnedNewestFirst() {
|
||||
String name = "ver-order-" + System.currentTimeMillis();
|
||||
String arn = call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r\"}")
|
||||
.then().statusCode(200).extract().jsonPath().getString("stateMachineArn");
|
||||
|
||||
// Publish three versions (1, 2, 3). AWS lists them newest first, and the Terraform provider
|
||||
// reads the version ARN off this list, so the order must be descending — even though the three
|
||||
// publishes land within the same (second-resolution) creationDate, the version-number tie-break
|
||||
// keeps 3 ahead of 2 ahead of 1.
|
||||
call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}").then().statusCode(200);
|
||||
call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}").then().statusCode(200);
|
||||
call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}").then().statusCode(200);
|
||||
// Re-publishing the same revision is idempotent and returns the existing version.
|
||||
call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200).body("stateMachineVersionArn", is(arn + ":1"));
|
||||
call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200).body("stateMachineVersionArn", is(arn + ":1"));
|
||||
|
||||
// Each update creates a new revision, so publishing those revisions advances the version.
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r2\",\"publish\":true}")
|
||||
.then().statusCode(200).body("stateMachineVersionArn", is(arn + ":2"));
|
||||
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r3\",\"publish\":true}")
|
||||
.then().statusCode(200).body("stateMachineVersionArn", is(arn + ":3"));
|
||||
|
||||
call("ListStateMachineVersions", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
@@ -91,10 +98,139 @@ class StepFunctionsVersionsIntegrationTest {
|
||||
@Test
|
||||
void createWithPublishReturnsVersionArn() {
|
||||
String name = "ver-pub-" + System.currentTimeMillis();
|
||||
call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r\",\"publish\":true}")
|
||||
String arn = call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r\","
|
||||
+ "\"publish\":true,\"versionDescription\":\"initial release\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineVersionArn", not(emptyOrNullString()))
|
||||
.body("stateMachineVersionArn", containsString(":1"));
|
||||
.body("stateMachineVersionArn", containsString(":1"))
|
||||
.extract().jsonPath().getString("stateMachineArn");
|
||||
|
||||
call("ListStateMachineVersions", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineVersions.size()", is(1))
|
||||
.body("stateMachineVersions[0].stateMachineVersionArn", is(arn + ":1"));
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + ":1\"}")
|
||||
.then().statusCode(200)
|
||||
.body("description", is("initial release"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithoutPublishReturnsExplicitNullVersionArn() {
|
||||
String name = "ver-unpublished-" + System.currentTimeMillis();
|
||||
Response response = call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().response();
|
||||
|
||||
assertTrue(response.asString().contains("\"stateMachineVersionArn\":null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createIsIdempotentForAwsContractFieldsAndIgnoresRoleAndTags() {
|
||||
String name = "ver-create-idempotent-" + System.currentTimeMillis();
|
||||
String originalRequest = "{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/original\","
|
||||
+ "\"tags\":[{\"key\":\"owner\",\"value\":\"original\"}],"
|
||||
+ "\"publish\":true,\"versionDescription\":\"initial release\"}";
|
||||
String arn = call("CreateStateMachine", originalRequest)
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineVersionArn", containsString(":1"))
|
||||
.extract().jsonPath().getString("stateMachineArn");
|
||||
|
||||
call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/ignored\","
|
||||
+ "\"tags\":[{\"key\":\"owner\",\"value\":\"ignored\"}],"
|
||||
+ "\"publish\":true,\"versionDescription\":\"initial release\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineArn", is(arn))
|
||||
.body("stateMachineVersionArn", is(arn + ":1"));
|
||||
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("roleArn", is("arn:aws:iam::000000000000:role/original"));
|
||||
call("ListTagsForResource", "{\"resourceArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("tags.size()", is(1))
|
||||
.body("tags[0].key", is("owner"))
|
||||
.body("tags[0].value", is("original"));
|
||||
|
||||
call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/original\","
|
||||
+ "\"publish\":true,\"versionDescription\":\"different\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("StateMachineAlreadyExists"));
|
||||
call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/original\","
|
||||
+ "\"tracingConfiguration\":{\"enabled\":true},"
|
||||
+ "\"publish\":true,\"versionDescription\":\"initial release\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("StateMachineAlreadyExists"));
|
||||
call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/original\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("StateMachineAlreadyExists"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publishHonorsRevisionAndDescriptionContract() {
|
||||
String name = "ver-revision-" + System.currentTimeMillis();
|
||||
String arn = call("CreateStateMachine",
|
||||
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("stateMachineArn");
|
||||
String revision = call(
|
||||
"DescribeStateMachine",
|
||||
"{\"stateMachineArn\":\"" + arn + "\"}")
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("revisionId");
|
||||
|
||||
call("PublishStateMachineVersion",
|
||||
"{\"stateMachineArn\":\"" + arn + "\",\"revisionId\":\""
|
||||
+ revision + "\",\"description\":\"first revision\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineVersionArn", is(arn + ":1"));
|
||||
call("PublishStateMachineVersion",
|
||||
"{\"stateMachineArn\":\"" + arn + "\",\"revisionId\":\""
|
||||
+ revision + "\",\"description\":\"ignored replay\"}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineVersionArn", is(arn + ":1"));
|
||||
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + ":1\"}")
|
||||
.then().statusCode(200)
|
||||
.body("description", is("first revision"));
|
||||
|
||||
call("PublishStateMachineVersion",
|
||||
"{\"stateMachineArn\":\"" + arn
|
||||
+ "\",\"revisionId\":\"00000000-0000-0000-0000-000000000000\"}")
|
||||
.then().statusCode(409)
|
||||
.body(containsString("ConflictException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidCreatePublishOptionsAndNamesAreRejectedBeforeStorage() {
|
||||
String name = "ver-invalid-publish-" + System.currentTimeMillis();
|
||||
String baseRequest = "{\"name\":\"" + name + "\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r\"";
|
||||
|
||||
call("CreateStateMachine",
|
||||
baseRequest + ",\"versionDescription\":\"requires publish\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("ValidationException"));
|
||||
call("CreateStateMachine", baseRequest + "}")
|
||||
.then().statusCode(200)
|
||||
.body("stateMachineArn", containsString(name));
|
||||
|
||||
call("CreateStateMachine",
|
||||
"{\"name\":\"invalid name\",\"definition\":\"" + DEF
|
||||
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r\"}")
|
||||
.then().statusCode(400)
|
||||
.body(containsString("InvalidName"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user