mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): refuse an update that has nothing to change (#5849)
* fix(cloudformation): refuse an update that has nothing to change UpdateStack ran a full update for a stack resubmitted as it was, ending UPDATE_COMPLETE, and CreateChangeSet created an AVAILABLE change set for it. CloudFormation refuses the update with "No updates are to be performed." and creates the change set FAILED, UNAVAILABLE, with "The submitted information didn't contain changes. Submit different information to create a change set."; the CDK and aws cloudformation deploy read that reason as "no changes". What CloudFormation compares was measured in eu-west-1: each active resource's Type, Properties, Metadata, DeletionPolicy, UpdateReplacePolicy and UpdatePolicy, and each active output's Value, Description and Export, with whatever does not depend on a resource resolved first, and the tags as a set (absent Tags keep the stack's). ComparedTemplate brings a template to that form: a new Description, an unused parameter, a DependsOn or a literal written as Fn::Join is no change, while a used mapping value, a Ref of a resource rewritten as Fn::Sub, or a dynamic reference whose stored value moved is one. Templates are compared as processed, AWS::Include fragments read again and the SAM transform applied with the stack's parameter values, and a stack with a nested stack is always updated. The change set diff uses the same form. The CDK deletes the FAILED change set and deletes it again by name before its next deploy, so DeleteChangeSet now answers success for a change set the stack does not have, as CloudFormation does. A stack set instance whose stack has nothing to change is left as it is. Tests that resubmitted an identical template to exercise an update add an output through CfnUpdates.forceUpdate, which is an update on AWS too. * fix(cloudformation): record dynamic reference values when an operation commits Answers the review of #5849. The value each dynamic reference resolved to is now recorded when the stack's operation commits, from the template the stack then has and keyed as ComparedTemplate hands the references over, instead of while the engine provisioned each resource. Recording and comparison so see the same strings, an Fn::Sub that also reads a resource included; an update that fails and rolls back records nothing and keeps the last deployment's values; a reference the template dropped is dropped; and AWS::RDS::DBInstance's master credentials, which its provisioner resolves itself with ssm-secure, are compared like any other reference. The values are kept as an HMAC-SHA256 under a random key of the stack's own rather than a bare SHA-256. ComparedTemplate keeps an AWS::NoValue inside a function it compares as written, and gives the array form of Fn::Sub the static variable substitution the string form has, its own variables left as written. A stack set instance with nothing to change succeeds whatever status an earlier rolled-back update left its stack in, and the change set that found it so is deleted. DeleteChangeSet by a change set's ARN alone succeeds when the change set is gone, as measured on CloudFormation in eu-west-1 on 2026-10-17. The comparison now catches only what it can meet: a template that does not parse, and the AwsException an AWS::Include, the SAM transform or an SSM parameter raises, which the update itself then reports.
This commit is contained in:
1 parent
c8de16ffc7
commit
197ccb5fb7
19 files changed
+1408
-40
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
/**
|
||||
* An UpdateStack whose template changes none of the stack's resources and outputs is refused with
|
||||
* "No updates are to be performed.", as on AWS, a new Description included. A test that re-applies
|
||||
* the same resources to exercise an update adds an output instead: on AWS that is an update which
|
||||
* leaves every resource as it is (measured on CloudFormation, eu-west-1, 2026-10-16).
|
||||
*/
|
||||
final class CfnUpdates {
|
||||
|
||||
/** The output {@link #forceUpdate} adds, for a test that compares a stack's outputs. */
|
||||
static final String FORCED_OUTPUT = "FlociForcedUpdate";
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private CfnUpdates() {
|
||||
}
|
||||
|
||||
/** {@code template}, JSON or YAML, as JSON with an output no deployed template carries. */
|
||||
static String forceUpdate(String template) {
|
||||
try {
|
||||
JsonNode parsed = template.stripLeading().startsWith("{")
|
||||
? MAPPER.readTree(template)
|
||||
: new CloudFormationYamlParser(MAPPER).parse(template);
|
||||
ObjectNode node = (ObjectNode) parsed;
|
||||
ObjectNode outputs = node.has("Outputs") ? (ObjectNode) node.get("Outputs") : node.putObject("Outputs");
|
||||
outputs.putObject(FORCED_OUTPUT).put("Value", String.valueOf(System.nanoTime()));
|
||||
return MAPPER.writeValueAsString(node);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("not a CloudFormation template", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -197,8 +197,9 @@ class CloudFormationEc2NetworkingIntegrationTest {
|
||||
assertTrue(ec2("DescribeInternetGateways").contains(out.get("IgwId")));
|
||||
|
||||
// The same template again: every id survives (the switch re-created all seven).
|
||||
cloudFormation("UpdateStack", template(vpcId, "10.40.0.0/24"));
|
||||
cloudFormation("UpdateStack", CfnUpdates.forceUpdate(template(vpcId, "10.40.0.0/24")));
|
||||
Map<String, String> again = XmlParser.extractPairs(describeStacks("UPDATE_COMPLETE"), "Outputs", "OutputKey", "OutputValue");
|
||||
again.remove(CfnUpdates.FORCED_OUTPUT);
|
||||
assertEquals(out, again, "an unchanged update must keep every networking resource");
|
||||
|
||||
// Tags are mutable: a dropped key goes, a changed value is written, the subnet stays.
|
||||
|
||||
+2
-2
@@ -424,7 +424,7 @@ class CloudFormationEventBusIntegrationTest {
|
||||
createStack(stackName, originalTemplate);
|
||||
assertStackStatus(stackName, "CREATE_COMPLETE");
|
||||
|
||||
updateStack(stackName, originalTemplate);
|
||||
updateStack(stackName, CfnUpdates.forceUpdate(originalTemplate));
|
||||
assertStackStatus(stackName, "UPDATE_COMPLETE");
|
||||
|
||||
updateStack(stackName, eventBusAndNamedRuleTemplate(busName, "after"));
|
||||
@@ -621,7 +621,7 @@ class CloudFormationEventBusIntegrationTest {
|
||||
createStack(stackName, originalTemplate);
|
||||
assertStackStatus(stackName, "CREATE_COMPLETE");
|
||||
|
||||
updateStack(stackName, originalTemplate);
|
||||
updateStack(stackName, CfnUpdates.forceUpdate(originalTemplate));
|
||||
assertStackStatus(stackName, "UPDATE_COMPLETE");
|
||||
|
||||
updateStack(stackName, eventBusWithPolicyTemplate(busName, "After"));
|
||||
|
||||
+22
-10
@@ -870,7 +870,7 @@ class CloudFormationIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template)
|
||||
.formParam("TemplateBody", CfnUpdates.forceUpdate(template))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -2765,8 +2765,10 @@ class CloudFormationIntegrationTest {
|
||||
return xml.substring(xml.lastIndexOf("<member>", idAt), xml.indexOf("</member>", idAt));
|
||||
}
|
||||
|
||||
// Measured against CloudFormation (eu-west-1, 2026-10-04): a change set the stack does not
|
||||
// have, on a stack in REVIEW_IN_PROGRESS as on one in CREATE_COMPLETE, is deleted with success.
|
||||
@Test
|
||||
void deleteChangeSet_nonExistentChangeSet_returnsError() {
|
||||
void deleteChangeSet_nonExistentChangeSet_succeeds() {
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
@@ -2793,7 +2795,6 @@ class CloudFormationIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Attempt to delete a changeset that does not exist
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteChangeSet")
|
||||
@@ -2802,8 +2803,18 @@ class CloudFormationIntegrationTest {
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ChangeSetNotFoundException"));
|
||||
.statusCode(200)
|
||||
.body(containsString("<DeleteChangeSetResult/>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeChangeSet")
|
||||
.formParam("StackName", "cs-error-stack")
|
||||
.formParam("ChangeSetName", "existing-changeset")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2930,7 +2941,7 @@ class CloudFormationIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template)
|
||||
.formParam("TemplateBody", CfnUpdates.forceUpdate(template))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -8397,13 +8408,14 @@ class CloudFormationIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body("Items.findAll { it.ApiId == '" + apiId + "' }.Name", hasItem("cfn-apigwv2-api-v2"));
|
||||
|
||||
// Idempotent re-deploy with no changes is a no-op (criterion #3): counts/ids unchanged
|
||||
// Re-deploying the same resources is a no-op for them (criterion #3): counts/ids unchanged.
|
||||
// An identical template is refused outright, so a new output forces the update.
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody",
|
||||
template.formatted("cfn-apigwv2-api-v2", "https://example.com/v2", "GET /things", "true"))
|
||||
.formParam("TemplateBody", CfnUpdates.forceUpdate(
|
||||
template.formatted("cfn-apigwv2-api-v2", "https://example.com/v2", "GET /things", "true")))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
@@ -10766,7 +10778,7 @@ class CloudFormationIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template)
|
||||
.formParam("TemplateBody", CfnUpdates.forceUpdate(template))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
|
||||
+577
@@ -0,0 +1,577 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.XmlParser;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import io.github.hectorvent.floci.services.ssm.SsmService;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
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;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* An update that changes none of the stack's resources and outputs. Measured against
|
||||
* CloudFormation (eu-west-1, 2026-10-03 and 2026-10-16): UpdateStack answers ValidationError "No
|
||||
* updates are to be performed." and changes nothing; a CreateChangeSet for it is created FAILED,
|
||||
* UNAVAILABLE, with "The submitted information didn't contain changes. Submit different information
|
||||
* to create a change set.". What is compared is each active resource's Type, Properties, Metadata,
|
||||
* DeletionPolicy, UpdateReplacePolicy and UpdatePolicy, and each active output, with whatever does
|
||||
* not depend on a resource resolved: a new Description, template Metadata, an unused parameter,
|
||||
* mapping or condition, a DependsOn, a literal written as Fn::Join, a parameter written as Fn::Sub
|
||||
* or an output whose condition is false is no change; a change to an active output, a resource's
|
||||
* Metadata, a used mapping value, a Ref of a resource rewritten as Fn::Sub, or a dynamic reference
|
||||
* whose stored value moved is an update. The CDK deletes the FAILED change set and deletes it again
|
||||
* by name before its next deploy; DeleteChangeSet answers success for a change set the stack does
|
||||
* not have, by name or by ARN, and ValidationError for a stack that does not exist (measured
|
||||
* 2026-10-04). Tags are part of what an update submits (measured 2026-10-16): the stack's own tags
|
||||
* in another order, or no Tags, change nothing; different tags, or an empty set on a tagged stack,
|
||||
* are an update that replaces them.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationNoChangesIntegrationTest {
|
||||
|
||||
private static final String TEMPLATE = """
|
||||
{"Resources": {"Topic": {"Type": "AWS::SNS::Topic", "Properties": {"TopicName": "%s"}}},
|
||||
"Outputs": {"Out": {"Value": "1"}}}""";
|
||||
|
||||
@Inject
|
||||
S3Service s3Service;
|
||||
|
||||
@Inject
|
||||
SsmService ssmService;
|
||||
|
||||
private final String suffix = Long.toString(System.nanoTime(), 36);
|
||||
private final List<String> stacksToDelete = new ArrayList<>();
|
||||
private final List<String> parametersToDelete = new ArrayList<>();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
for (String stackName : stacksToDelete) {
|
||||
request("DeleteStack", stackName).when().post("/");
|
||||
}
|
||||
stacksToDelete.clear();
|
||||
for (String parameter : parametersToDelete) {
|
||||
ssmService.deleteParameter(parameter, "us-east-1");
|
||||
}
|
||||
parametersToDelete.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
void anIdenticalUpdateIsRefusedAndChangesNothing() {
|
||||
String stackName = name("no-change");
|
||||
String template = TEMPLATE.formatted(name("no-change-topic"));
|
||||
create(stackName, template);
|
||||
String changeSetsBefore = listChangeSets(stackName).extract().asString();
|
||||
|
||||
update(stackName, template)
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>ValidationError</Code>"))
|
||||
.body(containsString("<Message>No updates are to be performed.</Message>"));
|
||||
update(stackName, template.replace("\n", "\n ").replace(": ", ": "))
|
||||
.statusCode(400)
|
||||
.body(containsString("No updates are to be performed."));
|
||||
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
listChangeSets(stackName).body(not(containsString("<ChangeSetName>update-")));
|
||||
assertEquals(changeSetsBefore.replaceAll("<RequestId>[^<]*</RequestId>", ""),
|
||||
listChangeSets(stackName).extract().asString().replaceAll("<RequestId>[^<]*</RequestId>", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aChangeToTheOutputsAloneIsAnUpdate() {
|
||||
String stackName = name("outputs-only");
|
||||
String template = TEMPLATE.formatted(name("outputs-only-topic"));
|
||||
create(stackName, template);
|
||||
|
||||
update(stackName, template.replace("\"Value\": \"1\"", "\"Value\": \"2\"")).statusCode(200);
|
||||
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stackName)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<OutputKey>Out</OutputKey>"))
|
||||
.body(containsString("<OutputValue>2</OutputValue>"));
|
||||
}
|
||||
|
||||
/**
|
||||
* What does not change a resource or an output is no update: a new Description, template
|
||||
* Metadata, an unused parameter, mapping or condition, a DependsOn, a literal written as
|
||||
* Fn::Join, a parameter written as Fn::Sub, an Fn::If whose other branch changed, and an output
|
||||
* whose condition is false.
|
||||
*/
|
||||
@Test
|
||||
void whatChangesNoResourceOrOutputIsNoUpdate() {
|
||||
String template = """
|
||||
{"Parameters": {"P": {"Type": "String", "Default": "x"}},
|
||||
"Conditions": {"Never": {"Fn::Equals": ["a", "b"]}},
|
||||
"Resources": {
|
||||
"A": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String", "Value": "v"}},
|
||||
"B": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String", "Value": {"Ref": "P"}}}},
|
||||
"Outputs": {"Out": {"Value": "o"}, "Gated": {"Condition": "Never", "Value": "g"}}}""";
|
||||
String stackName = name("no-change-forms");
|
||||
create(stackName, template);
|
||||
|
||||
for (String same : new String[] {
|
||||
template.replace("{\"Parameters\"", "{\"Description\": \"new\", \"Metadata\": {\"k\": \"v\"}, \"Parameters\""),
|
||||
template.replace("\"Default\": \"x\"}}", "\"Default\": \"x\"}, \"Unused\": {\"Type\": \"String\", \"Default\": \"u\"}}, "
|
||||
+ "\"Mappings\": {\"M\": {\"k\": {\"v\": \"m\"}}}"),
|
||||
template.replace("\"Type\": \"String\", \"Value\": \"v\"}}", "\"Type\": \"String\", \"Value\": \"v\"}, \"DependsOn\": \"B\"}"),
|
||||
template.replace("\"Value\": \"v\"", "\"Value\": {\"Fn::Join\": [\"\", [\"v\"]]}"),
|
||||
template.replace("{\"Ref\": \"P\"}", "{\"Fn::Sub\": \"${P}\"}"),
|
||||
template.replace("\"Value\": \"v\"", "\"Value\": {\"Fn::If\": [\"Never\", \"other\", \"v\"]}"),
|
||||
template.replace("\"Value\": \"g\"", "\"Value\": \"g2\""),
|
||||
}) {
|
||||
update(stackName, same)
|
||||
.statusCode(400)
|
||||
.body(containsString("No updates are to be performed."));
|
||||
}
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/**
|
||||
* A Ref of a resource is compared as written: rewritten as Fn::Sub, it is an update, as a new
|
||||
* Metadata on a resource is.
|
||||
*/
|
||||
@Test
|
||||
void whatReadsAResourceIsComparedAsWritten() {
|
||||
String template = """
|
||||
{"Resources": {
|
||||
"A": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String", "Value": "a"}},
|
||||
"B": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String", "Value": {"Ref": "A"}}}}}""";
|
||||
String stackName = name("as-written");
|
||||
create(stackName, template);
|
||||
|
||||
String rewritten = template.replace("{\"Ref\": \"A\"}", "{\"Fn::Sub\": \"${A}\"}");
|
||||
update(stackName, rewritten).statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
|
||||
update(stackName, rewritten.replace("\"Value\": \"a\"}}", "\"Value\": \"a\"}, \"Metadata\": {\"k\": \"v\"}}"))
|
||||
.statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/** A mapping value a resource uses is resolved: changed, the resource is modified. */
|
||||
@Test
|
||||
void aUsedMappingValueIsAChange() {
|
||||
String template = """
|
||||
{"Mappings": {"M": {"k": {"v": "%s"}}},
|
||||
"Resources": {"B": {"Type": "AWS::SSM::Parameter",
|
||||
"Properties": {"Type": "String", "Value": {"Fn::FindInMap": ["M", "k", "v"]}}}}}""";
|
||||
String stackName = name("used-mapping");
|
||||
create(stackName, template.formatted("first"));
|
||||
|
||||
changeSet(stackName, "mapping", template.formatted("second")).when().post("/").then().statusCode(200);
|
||||
describeChangeSet(stackName, "mapping")
|
||||
.body(containsString("<Status>CREATE_COMPLETE</Status>"))
|
||||
.body(containsString("<Action>Modify</Action>"))
|
||||
.body(containsString("<LogicalResourceId>B</LogicalResourceId>"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A dynamic reference compares as the value it resolves to: identical, the template is an
|
||||
* update once the stored value moved, and the resource takes the new value.
|
||||
*/
|
||||
@Test
|
||||
void aDynamicReferenceWhoseValueMovedIsAChange() {
|
||||
String source = "/no-change/source-" + suffix;
|
||||
ssmService.putParameter(source, "first", "String", null, true, "us-east-1");
|
||||
parametersToDelete.add(source);
|
||||
String template = """
|
||||
{"Resources": {"Copy": {"Type": "AWS::SSM::Parameter",
|
||||
"Properties": {"Name": "%s-copy", "Type": "String", "Value": "{{resolve:ssm:%s}}"}}}}"""
|
||||
.formatted(source, source);
|
||||
String stackName = name("moved-reference");
|
||||
create(stackName, template);
|
||||
|
||||
update(stackName, template)
|
||||
.statusCode(400)
|
||||
.body(containsString("No updates are to be performed."));
|
||||
|
||||
ssmService.putParameter(source, "second", "String", null, true, "us-east-1");
|
||||
update(stackName, template).statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals("second", ssmService.getParameter(source + "-copy", "us-east-1").getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* A dynamic reference inside an Fn::Sub that reads a resource compares as the value it resolves
|
||||
* to, the resource read left as written: unchanged, the template is no update; once the stored
|
||||
* value moved, it is one.
|
||||
*/
|
||||
@Test
|
||||
void aDynamicReferenceBesideAResourceReadComparesByItsValue() {
|
||||
String source = "/no-change/beside-" + suffix;
|
||||
ssmService.putParameter(source, "first", "String", null, true, "us-east-1");
|
||||
parametersToDelete.add(source);
|
||||
String template = """
|
||||
{"Resources": {
|
||||
"A": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String", "Value": "a"}},
|
||||
"B": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String",
|
||||
"Value": {"Fn::Sub": "${A}-{{resolve:ssm:%s}}"}}}}}""".formatted(source);
|
||||
String stackName = name("beside-resource");
|
||||
create(stackName, template);
|
||||
|
||||
update(stackName, template)
|
||||
.statusCode(400)
|
||||
.body(containsString("No updates are to be performed."));
|
||||
|
||||
ssmService.putParameter(source, "second", "String", null, true, "us-east-1");
|
||||
update(stackName, template).statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/**
|
||||
* An update that fails rolls back to what the stack had, the dynamic reference values it was
|
||||
* deployed with included: retried after a stored value moved, it is still an update.
|
||||
*/
|
||||
@Test
|
||||
void aFailedUpdateLeavesTheDeployedDynamicReferenceValues() {
|
||||
String source = "/no-change/rolled-back-" + suffix;
|
||||
ssmService.putParameter(source, "first", "String", null, true, "us-east-1");
|
||||
parametersToDelete.add(source);
|
||||
String copy = """
|
||||
"Copy": {"Type": "AWS::SSM::Parameter",
|
||||
"Properties": {"Type": "String", "Value": "{{resolve:ssm:%s}}"}}""".formatted(source);
|
||||
String template = "{\"Resources\": {" + copy + "}}";
|
||||
// A nested stack without a TemplateURL fails once Copy took the new value.
|
||||
String failing = "{\"Resources\": {" + copy + ", \"Nested\": {\"Type\": \"AWS::CloudFormation::Stack\","
|
||||
+ " \"DependsOn\": \"Copy\", \"Properties\": {}}}}";
|
||||
String stackName = name("rolled-back");
|
||||
create(stackName, template);
|
||||
|
||||
ssmService.putParameter(source, "second", "String", null, true, "us-east-1");
|
||||
update(stackName, failing).statusCode(200);
|
||||
assertEquals("UPDATE_ROLLBACK_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
|
||||
update(stackName, template).statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/**
|
||||
* What reads a resource is compared as written, an AWS::NoValue in it included: an Fn::Join that
|
||||
* drops one is an update.
|
||||
*/
|
||||
@Test
|
||||
void aNoValueInsideAResourceReadIsPartOfWhatIsWritten() {
|
||||
String template = """
|
||||
{"Resources": {
|
||||
"A": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String", "Value": "a"}},
|
||||
"B": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String",
|
||||
"Value": {"Fn::Join": ["-", [{"Ref": "A"}, "x", {"Ref": "AWS::NoValue"}]]}}}}}""";
|
||||
String stackName = name("novalue-written");
|
||||
create(stackName, template);
|
||||
|
||||
update(stackName, template.replace(", {\"Ref\": \"AWS::NoValue\"}", "")).statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/**
|
||||
* The array form of an Fn::Sub that reads a resource has its other variables replaced by their
|
||||
* values too, those its own map defines left as written: an AWS::Region written as its value is
|
||||
* no update.
|
||||
*/
|
||||
@Test
|
||||
void anFnSubArrayReadingAResourceComparesItsOtherVariablesByValue() {
|
||||
String template = """
|
||||
{"Resources": {
|
||||
"A": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String", "Value": "a"}},
|
||||
"B": {"Type": "AWS::SSM::Parameter", "Properties": {"Type": "String",
|
||||
"Value": {"Fn::Sub": ["${A}-${AWS::Region}-${X}", {"X": "x"}]}}}}}""";
|
||||
String stackName = name("sub-array");
|
||||
create(stackName, template);
|
||||
|
||||
update(stackName, template.replace("${AWS::Region}", "us-east-1"))
|
||||
.statusCode(400)
|
||||
.body(containsString("No updates are to be performed."));
|
||||
update(stackName, template.replace("{\"X\": \"x\"}", "{\"X\": \"y\"}")).statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/**
|
||||
* A transformed template is compared as CloudFormation processes it: the SAM transform applied,
|
||||
* so resubmitting an unchanged SAM template is not an update either.
|
||||
*/
|
||||
@Test
|
||||
void anUnchangedSamTemplateIsRefused() {
|
||||
String template = """
|
||||
{"Transform": "AWS::Serverless-2016-10-31",
|
||||
"Resources": {"Table": {"Type": "AWS::Serverless::SimpleTable",
|
||||
"Properties": {"TableName": "%s"}}}}""".formatted(name("sam-table"));
|
||||
String stackName = name("no-change-sam");
|
||||
create(stackName, template);
|
||||
|
||||
update(stackName, template)
|
||||
.statusCode(400)
|
||||
.body(containsString("No updates are to be performed."));
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/**
|
||||
* The SAM transform is applied with the stack's parameter values, as execution applies it: a
|
||||
* version SAM names after a hash of its code, which a parameter given a value other than its
|
||||
* default changes, compares equal, and resubmitting the template with the same values is not an
|
||||
* update.
|
||||
*/
|
||||
@Test
|
||||
void anUnchangedSamTemplateIsComparedWithItsParameterValues() {
|
||||
String template = """
|
||||
{"Transform": "AWS::Serverless-2016-10-31",
|
||||
"Parameters": {"Release": {"Type": "String", "Default": "first"}},
|
||||
"Resources": {"Function": {"Type": "AWS::Serverless::Function",
|
||||
"Properties": {"FunctionName": "%s", "Handler": "index.handler",
|
||||
"Runtime": "nodejs20.x", "AutoPublishAlias": "live",
|
||||
"InlineCode": {"Fn::Sub": "exports.handler = async () => '${Release}';"}}}}}"""
|
||||
.formatted(name("sam-params-func"));
|
||||
String stackName = name("no-change-sam-params");
|
||||
request("CreateStack", stackName).formParam("TemplateBody", template)
|
||||
.formParam("Capabilities.member.1", "CAPABILITY_IAM")
|
||||
.formParam("Parameters.member.1.ParameterKey", "Release")
|
||||
.formParam("Parameters.member.1.ParameterValue", "second")
|
||||
.when().post("/").then().statusCode(200);
|
||||
stacksToDelete.add(stackName);
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
|
||||
request("UpdateStack", stackName).formParam("TemplateBody", template)
|
||||
.formParam("Capabilities.member.1", "CAPABILITY_IAM")
|
||||
.formParam("Parameters.member.1.ParameterKey", "Release")
|
||||
.formParam("Parameters.member.1.ParameterValue", "second")
|
||||
.when().post("/").then()
|
||||
.statusCode(400)
|
||||
.body(containsString("No updates are to be performed."));
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS::Include fragments are merged before the comparison, and read again: the same template
|
||||
* with the same fragment is not an update, and with the fragment changed in S3 it is.
|
||||
*/
|
||||
@Test
|
||||
void anIncludeIsComparedWithItsFragmentReadAgain() {
|
||||
String bucket = name("include");
|
||||
s3Service.createBucket(bucket, "us-east-1");
|
||||
putFragment(bucket, "Description: first\n");
|
||||
String template = """
|
||||
Resources:
|
||||
Topic:
|
||||
Type: AWS::SNS::Topic
|
||||
Metadata:
|
||||
Fn::Transform:
|
||||
Name: AWS::Include
|
||||
Parameters:
|
||||
Location: s3://%s/fragment.yaml
|
||||
Properties:
|
||||
TopicName: %s
|
||||
""".formatted(bucket, name("include-topic"));
|
||||
String stackName = name("no-change-include");
|
||||
try {
|
||||
create(stackName, template);
|
||||
|
||||
update(stackName, template)
|
||||
.statusCode(400)
|
||||
.body(containsString("No updates are to be performed."));
|
||||
|
||||
putFragment(bucket, "Description: second\n");
|
||||
update(stackName, template).statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
} finally {
|
||||
s3Service.deleteObject(bucket, "fragment.yaml");
|
||||
s3Service.deleteBucket(bucket);
|
||||
}
|
||||
}
|
||||
|
||||
private void putFragment(String bucket, String content) {
|
||||
s3Service.putObject(bucket, "fragment.yaml", content.getBytes(StandardCharsets.UTF_8), "text/yaml", Map.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aChangeSetWithNothingToChangeIsCreatedFailed() {
|
||||
String stackName = name("change-set-same");
|
||||
String template = TEMPLATE.formatted(name("change-set-same-topic"));
|
||||
create(stackName, template);
|
||||
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateChangeSet")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("ChangeSetName", "same")
|
||||
.formParam("ChangeSetType", "UPDATE")
|
||||
.formParam("TemplateBody", template)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeChangeSet")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("ChangeSetName", "same")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Status>FAILED</Status>"))
|
||||
.body(containsString("<ExecutionStatus>UNAVAILABLE</ExecutionStatus>"))
|
||||
.body(containsString("<StatusReason>The submitted information didn"))
|
||||
.body(containsString("t contain changes. Submit different information to create a change set.</StatusReason>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsArePartOfWhatAnUpdateSubmits() {
|
||||
String stackName = name("tags");
|
||||
String template = TEMPLATE.formatted(name("tags-topic"));
|
||||
withTags(request("CreateStack", stackName).formParam("TemplateBody", template), "Env", "a", "Team", "x")
|
||||
.when().post("/").then().statusCode(200);
|
||||
stacksToDelete.add(stackName);
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
|
||||
withTags(request("UpdateStack", stackName).formParam("TemplateBody", template), "Team", "x", "Env", "a")
|
||||
.when().post("/").then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Message>No updates are to be performed.</Message>"));
|
||||
update(stackName, template)
|
||||
.statusCode(400)
|
||||
.body(containsString("<Message>No updates are to be performed.</Message>"));
|
||||
assertEquals(Map.of("Env", "a", "Team", "x"), tags(stackName));
|
||||
|
||||
withTags(changeSet(stackName, "same-tags", template), "Env", "a", "Team", "x")
|
||||
.when().post("/").then().statusCode(200);
|
||||
describeChangeSet(stackName, "same-tags").body(containsString("<Status>FAILED</Status>"));
|
||||
withTags(changeSet(stackName, "other-tags", template), "Env", "b")
|
||||
.when().post("/").then().statusCode(200);
|
||||
describeChangeSet(stackName, "other-tags")
|
||||
.body(containsString("<Status>CREATE_COMPLETE</Status>"))
|
||||
.body(containsString("<ExecutionStatus>AVAILABLE</ExecutionStatus>"));
|
||||
|
||||
withTags(request("UpdateStack", stackName).formParam("TemplateBody", template), "Env", "b")
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(Map.of("Env", "b"), tags(stackName));
|
||||
|
||||
request("UpdateStack", stackName).formParam("TemplateBody", template).formParam("Tags", "")
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(Map.of(), tags(stackName));
|
||||
request("UpdateStack", stackName).formParam("TemplateBody", template).formParam("Tags", "")
|
||||
.when().post("/").then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Message>No updates are to be performed.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theChangeSetTheCdkDeletedCanBeDeletedAgain() {
|
||||
String stackName = name("delete-again");
|
||||
String template = TEMPLATE.formatted(name("delete-again-topic"));
|
||||
create(stackName, template);
|
||||
String id = given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateChangeSet")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("ChangeSetName", "cdk-deploy-change-set")
|
||||
.formParam("ChangeSetType", "UPDATE")
|
||||
.formParam("TemplateBody", template)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().xmlPath().getString("CreateChangeSetResponse.CreateChangeSetResult.Id");
|
||||
|
||||
deleteChangeSet(stackName, "cdk-deploy-change-set").statusCode(200);
|
||||
deleteChangeSet(stackName, "cdk-deploy-change-set")
|
||||
.statusCode(200)
|
||||
.body(containsString("<DeleteChangeSetResult/>"));
|
||||
deleteChangeSet(stackName, id).statusCode(200);
|
||||
// By its ARN alone too, with no StackName (measured 2026-10-17).
|
||||
deleteChangeSet(null, id)
|
||||
.statusCode(200)
|
||||
.body(containsString("<DeleteChangeSetResult/>"));
|
||||
deleteChangeSet(name("delete-again-missing"), "cdk-deploy-change-set")
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>ValidationError</Code>"));
|
||||
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
/** {@code stackName} null sends none: the change set is named by its ARN alone. */
|
||||
private static ValidatableResponse deleteChangeSet(String stackName, String changeSetName) {
|
||||
RequestSpecification request = given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteChangeSet")
|
||||
.formParam("ChangeSetName", changeSetName);
|
||||
if (stackName != null) {
|
||||
request.formParam("StackName", stackName);
|
||||
}
|
||||
return request.when().post("/").then();
|
||||
}
|
||||
|
||||
/** A name unique to this run, so a rerun in the same JVM never meets a stack of an earlier one. */
|
||||
private String name(String base) {
|
||||
return "no-change-" + base + "-" + suffix;
|
||||
}
|
||||
|
||||
private void create(String stackName, String template) {
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template)
|
||||
.when().post("/").then().statusCode(200);
|
||||
stacksToDelete.add(stackName);
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
}
|
||||
|
||||
private static ValidatableResponse update(String stackName, String template) {
|
||||
return given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", template)
|
||||
.when().post("/").then();
|
||||
}
|
||||
|
||||
private static RequestSpecification request(String action, String stackName) {
|
||||
return given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", action)
|
||||
.formParam("StackName", stackName);
|
||||
}
|
||||
|
||||
private static RequestSpecification changeSet(String stackName, String changeSetName, String template) {
|
||||
return request("CreateChangeSet", stackName)
|
||||
.formParam("ChangeSetName", changeSetName)
|
||||
.formParam("ChangeSetType", "UPDATE")
|
||||
.formParam("TemplateBody", template);
|
||||
}
|
||||
|
||||
private static ValidatableResponse describeChangeSet(String stackName, String changeSetName) {
|
||||
return request("DescribeChangeSet", stackName)
|
||||
.formParam("ChangeSetName", changeSetName)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static RequestSpecification withTags(RequestSpecification request, String... keysAndValues) {
|
||||
for (int i = 0; i < keysAndValues.length; i += 2) {
|
||||
int member = i / 2 + 1;
|
||||
request.formParam("Tags.member." + member + ".Key", keysAndValues[i])
|
||||
.formParam("Tags.member." + member + ".Value", keysAndValues[i + 1]);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private static Map<String, String> tags(String stackName) {
|
||||
String xml = request("DescribeStacks", stackName).when().post("/")
|
||||
.then().statusCode(200).extract().asString();
|
||||
return XmlParser.extractPairs(xml, "member", "Key", "Value");
|
||||
}
|
||||
|
||||
private static ValidatableResponse listChangeSets(String stackName) {
|
||||
return given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListChangeSets")
|
||||
.formParam("StackName", stackName)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -410,7 +410,9 @@ class CloudFormationPipesCleanupIntegrationTest {
|
||||
assertEquals("UPDATE_ROLLBACK_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
|
||||
Mockito.doCallRealMethod().when(pipesService).deletePipe(eq(replacementName), anyString());
|
||||
updateStack(stackName, renameRollbackTemplate(priorName, ""));
|
||||
// The rollback left the stack on this very template, which AWS refuses to update to with
|
||||
// "No updates are to be performed.": a new output makes it an update.
|
||||
updateStack(stackName, CfnUpdates.forceUpdate(renameRollbackTemplate(priorName, "")));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ class CloudFormationRdsIntegrationTest {
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", dbSubnetGroupTemplate(groupName))
|
||||
.formParam("TemplateBody", CfnUpdates.forceUpdate(dbSubnetGroupTemplate(groupName)))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ class CloudFormationRollbackCompleteUpdateIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStack")
|
||||
.formParam("StackName", stackName)
|
||||
.formParam("TemplateBody", topicTemplate(topicName))
|
||||
.formParam("TemplateBody", CfnUpdates.forceUpdate(topicTemplate(topicName)))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
|
||||
+1
-1
@@ -235,7 +235,7 @@ class CloudFormationSecurityGroupRulesIntegrationTest {
|
||||
assertEquals(1, occurrences(describeGroup(groupId), "<cidrIp>10.3.0.0/16</cidrIp>"));
|
||||
|
||||
// Unchanged template: the append-only authorize API would double the permission.
|
||||
updateStack(stackName, standaloneIngressTemplate(groupId, "10.3.0.0/16"));
|
||||
updateStack(stackName, CfnUpdates.forceUpdate(standaloneIngressTemplate(groupId, "10.3.0.0/16")));
|
||||
assertEquals(1, occurrences(describeGroup(groupId), "<cidrIp>10.3.0.0/16</cidrIp>"),
|
||||
"update duplicated an unchanged standalone rule");
|
||||
|
||||
|
||||
+141
@@ -287,6 +287,147 @@ class CloudFormationStackSetsIntegrationTest {
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* An UpdateStackSet that changes nothing for an instance leaves its stack as it is: the
|
||||
* instance succeeds and its stack is not updated.
|
||||
*/
|
||||
@Test
|
||||
void anUpdateStackSetWithNothingToChangeLeavesTheInstanceStackAsItIs() {
|
||||
String setName = "same-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String queue = "same-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStackSet")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("TemplateBody", queueTemplate(queue))
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStackInstances")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("Accounts.member.1", ACCOUNT_B)
|
||||
.formParam("Regions.member.1", REGION)
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
assertQueueVisible(ACCOUNT_B, queue);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStackSet")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("TemplateBody", queueTemplate(queue))
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", "StackSet-" + setName + "-" + ACCOUNT_B)
|
||||
.header("Authorization", auth(ACCOUNT_B, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListStackSetOperations")
|
||||
.formParam("StackSetName", setName)
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Action>UPDATE</Action>"))
|
||||
.body(not(containsString("<Status>FAILED</Status>")));
|
||||
// The change set that found nothing to change is not left on the instance's stack.
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListChangeSets")
|
||||
.formParam("StackName", "StackSet-" + setName + "-" + ACCOUNT_B)
|
||||
.header("Authorization", auth(ACCOUNT_B, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(not(containsString("<Status>FAILED</Status>")));
|
||||
}
|
||||
|
||||
/**
|
||||
* An update that failed rolls the instance's stack back to its template. Updating the stack set
|
||||
* back to that template has nothing to change, and the instance succeeds.
|
||||
*/
|
||||
@Test
|
||||
void anUpdateStackSetBackToARolledBackInstancesTemplateSucceeds() {
|
||||
String setName = "back-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String queue = "back-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String failing = """
|
||||
{"Resources":{"Q":{"Type":"AWS::SQS::Queue","Properties":{"QueueName":"%s"}},
|
||||
"Nested":{"Type":"AWS::CloudFormation::Stack","Properties":{}}}}
|
||||
""".formatted(queue);
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStackSet")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("TemplateBody", queueTemplate(queue))
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStackInstances")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("Accounts.member.1", ACCOUNT_B)
|
||||
.formParam("Regions.member.1", REGION)
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStackSet")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("TemplateBody", failing)
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", "StackSet-" + setName + "-" + ACCOUNT_B)
|
||||
.header("Authorization", auth(ACCOUNT_B, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<StackStatus>UPDATE_ROLLBACK_COMPLETE</StackStatus>"));
|
||||
|
||||
String operationId = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "UpdateStackSet")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("TemplateBody", queueTemplate(queue))
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().path("UpdateStackSetResponse.UpdateStackSetResult.OperationId");
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStackSetOperation")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("OperationId", operationId)
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Status>SUCCEEDED</Status>"));
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DescribeStackInstance")
|
||||
.formParam("StackSetName", setName)
|
||||
.formParam("StackInstanceAccount", ACCOUNT_B)
|
||||
.formParam("StackInstanceRegion", REGION)
|
||||
.header("Authorization", auth(ADMIN, "cloudformation"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<DetailedStatus>SUCCEEDED</DetailedStatus>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateStackSetReappliesToExistingInstances() {
|
||||
String setName = "upd-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
Reference in new issue
Block a user