mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudformation): default CreateChangeSet type to UPDATE (#5287)
Follow-up to #5015. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
673c809eff
commit
f6e76bbe30
2 files changed
+69
-4
No files matched your search
+2
-3
@@ -391,7 +391,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
// was already released, losing an accepted change set or corrupting the map's links. Only
|
||||
// persistStack() stays outside: it is storage I/O, and compute()'s contract is that the
|
||||
// remapping function does short, non-blocking work.
|
||||
boolean isCreateType = changeSetType == null || "CREATE".equalsIgnoreCase(changeSetType);
|
||||
boolean isCreateType = "CREATE".equalsIgnoreCase(changeSetType);
|
||||
// An update names its stack by name or stack ID; the map is keyed by name. One that names no
|
||||
// live stack is keyed as given, so it lands in the missing-stack branch below.
|
||||
Stack live = isCreateType ? null : resolveStack(stackName, region, accountId);
|
||||
@@ -409,7 +409,6 @@ public class CloudFormationService implements ResourceProvider {
|
||||
// matching stack-level event (as AWS and LocalStack do) so DescribeStackEvents is
|
||||
// non-empty straight after change-set creation — tooling such as the AWS SAM CLI
|
||||
// reads StackEvents[0] there and otherwise fails with an IndexError.
|
||||
// (CreateChangeSet defaults a null type to CREATE.)
|
||||
if (isCreateType) {
|
||||
addEvent(target, target.getStackName(), target.getStackId(),
|
||||
"AWS::CloudFormation::Stack", "REVIEW_IN_PROGRESS", "User Initiated");
|
||||
@@ -445,7 +444,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
cs.setChangeSetName(changeSetName);
|
||||
cs.setStackName(canonicalStackName);
|
||||
cs.setStackId(target.getStackId());
|
||||
cs.setChangeSetType(changeSetType != null ? changeSetType : "CREATE");
|
||||
cs.setChangeSetType(changeSetType != null ? changeSetType : "UPDATE");
|
||||
cs.setTemplateBody(resolvedTemplate);
|
||||
cs.setParameters(parameters);
|
||||
cs.setCapabilities(capabilities);
|
||||
|
||||
+67
-1
@@ -1,9 +1,11 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -20,7 +22,8 @@ import static org.hamcrest.Matchers.not;
|
||||
/**
|
||||
* UpdateStack and CreateChangeSet take "the name or the unique stack ID" as StackName. An UPDATE
|
||||
* change set given the stack ID has to land on the stack that ID names, not on a new key spelled
|
||||
* like the ARN (floci-io/floci#4842).
|
||||
* like the ARN (floci-io/floci#4842). A CreateChangeSet without a ChangeSetType is an UPDATE, as it
|
||||
* is on AWS.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationStackIdUpdateIntegrationTest {
|
||||
@@ -44,6 +47,12 @@ class CloudFormationStackIdUpdateIntegrationTest {
|
||||
}
|
||||
""";
|
||||
|
||||
@Inject
|
||||
CloudFormationService cfnService;
|
||||
|
||||
@Inject
|
||||
EmulatorConfig config;
|
||||
|
||||
private final Set<String> stacksToDelete = new LinkedHashSet<>();
|
||||
|
||||
@BeforeAll
|
||||
@@ -205,6 +214,63 @@ class CloudFormationStackIdUpdateIntegrationTest {
|
||||
.body(not(containsString("update-by-stale-stack-id")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void changeSetWithoutATypeIsAnUpdateOfTheExistingStack() {
|
||||
String stackName = "stack-id-untyped-" + Long.toString(System.nanoTime(), 36);
|
||||
createStack(stackName);
|
||||
|
||||
withParameters(stackName, "second")
|
||||
.formParam("Action", "CreateChangeSet")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("ChangeSetName", "untyped")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeChangeSet")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("ChangeSetName", "untyped")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Action>Modify</Action>"));
|
||||
assertThat(cfnService.describeChangeSet(stackName, "untyped", config.defaultRegion()).getChangeSetType(),
|
||||
equalTo("UPDATE"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ExecuteChangeSet")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("ChangeSetName", "untyped")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
assertThat(CfnStackWaits.awaitTerminal(stackName).status(), equalTo("UPDATE_COMPLETE"));
|
||||
assertThat(parameterValue(stackName), equalTo("second"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void changeSetWithoutATypeOnAMissingStackIsAValidationError() {
|
||||
String stackName = "stack-id-untyped-missing-" + Long.toString(System.nanoTime(), 36);
|
||||
|
||||
withParameters(stackName, "first")
|
||||
.formParam("Action", "CreateChangeSet")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("ChangeSetName", "untyped")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>ValidationError</Code>"))
|
||||
.body(containsString("Stack with id " + stackName + " does not exist"));
|
||||
}
|
||||
|
||||
private String createStack(String stackName) {
|
||||
stacksToDelete.add(stackName);
|
||||
String stackId = withParameters(stackName, "first")
|
||||
|
||||
Reference in new issue
Block a user