mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): an update that adds a create-only value replaces the resource (#8471)
This commit is contained in:
1 parent
95fa805590
commit
b2def4f421
6 files changed
+124
-39
No files matched your search
+57
-2
@@ -159,13 +159,13 @@ class CfnReplacementIntegrationTest {
|
||||
SUBNET_GROUP_REPLACED,
|
||||
createOnlyRow("SQS queue explicit QueueName removed", "", "", SQS_TYPE,
|
||||
"\"QueueName\": \"repl-q-removed\"", "\"VisibilityTimeout\": 30", "True", false, null),
|
||||
new Row("SQS queue QueueName dropped by Fn::If choosing AWS::NoValue",
|
||||
new Row("SQS queue QueueName dropped by Fn::If choosing AWS::NoValue, beside an updatable change",
|
||||
namedByCondition(SQS_TYPE, "QueueName", "repl-q-if", "[\"x\", \"x\"]"),
|
||||
namedByCondition(SQS_TYPE, "QueueName", "repl-q-if", "[\"x\", \"y\"]"),
|
||||
"Subject", "True", true, null),
|
||||
createOnlyRow("S3 bucket explicit BucketName removed", "", "", S3_TYPE,
|
||||
"\"BucketName\": \"repl-s3-removed\"", "", "True", false, null),
|
||||
new Row("S3 bucket BucketName dropped by Fn::If choosing AWS::NoValue",
|
||||
new Row("S3 bucket BucketName dropped by Fn::If choosing AWS::NoValue, beside an updatable change",
|
||||
namedByCondition(S3_TYPE, "BucketName", "repl-s3-if", "[\"x\", \"x\"]"),
|
||||
namedByCondition(S3_TYPE, "BucketName", "repl-s3-if", "[\"x\", \"y\"]"),
|
||||
"Subject", "True", true, null),
|
||||
@@ -178,6 +178,45 @@ class CfnReplacementIntegrationTest {
|
||||
"\"RepositoryName\": \"repl-ecr-named\"", "", "True", false, null),
|
||||
createOnlyRow("DynamoDB table explicit TableName removed", "", "", "AWS::DynamoDB::Table",
|
||||
DDB_KEYS + ", \"TableName\": \"repl-ddb-removed\"", DDB_KEYS, "True", false, null),
|
||||
new Row("log group given a Properties block that sets its name",
|
||||
"{\"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\"}}}",
|
||||
"{\"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\","
|
||||
+ " \"Properties\": {\"LogGroupName\": \"repl-added-properties\"}}}}",
|
||||
"Subject", "True", true, null),
|
||||
new Row("log group given a Properties block with only an updatable property",
|
||||
"{\"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\"}}}",
|
||||
"{\"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\","
|
||||
+ " \"Properties\": {\"RetentionInDays\": 7}}}}",
|
||||
"Subject", "False", false, null),
|
||||
new Row("log group whose existing Properties block gains its name",
|
||||
"{\"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\","
|
||||
+ " \"Properties\": {\"RetentionInDays\": 7}}}}",
|
||||
"{\"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\","
|
||||
+ " \"Properties\": {\"RetentionInDays\": 7,"
|
||||
+ " \"LogGroupName\": \"repl-added-name\"}}}}",
|
||||
"Subject", "True", true, null),
|
||||
new Row("log group whose added LogGroupName is an Fn::If choosing AWS::NoValue, beside an updatable change",
|
||||
"{\"Conditions\": {\"Named\": {\"Fn::Equals\": [\"x\", \"y\"]}},"
|
||||
+ " \"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\","
|
||||
+ " \"Properties\": {\"RetentionInDays\": 7}}}}",
|
||||
"{\"Conditions\": {\"Named\": {\"Fn::Equals\": [\"x\", \"y\"]}},"
|
||||
+ " \"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\","
|
||||
+ " \"Properties\": {\"RetentionInDays\": 14,"
|
||||
+ " \"LogGroupName\": {\"Fn::If\": [\"Named\", \"repl-if-novalue\","
|
||||
+ " {\"Ref\": \"AWS::NoValue\"}]}}}}}",
|
||||
"Subject", "False", false, null),
|
||||
new Row("log group whose added LogGroupName is an Fn::If choosing AWS::NoValue while a tag reads another stack's output",
|
||||
"{\"Conditions\": {\"Named\": {\"Fn::Equals\": [\"x\", \"y\"]}},"
|
||||
+ " \"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\","
|
||||
+ " \"Properties\": {\"RetentionInDays\": 7}}}}",
|
||||
"{\"Conditions\": {\"Named\": {\"Fn::Equals\": [\"x\", \"y\"]}},"
|
||||
+ " \"Resources\": {\"Subject\": {\"Type\": \"AWS::Logs::LogGroup\","
|
||||
+ " \"Properties\": {\"RetentionInDays\": 14,"
|
||||
+ " \"Tags\": [{\"Key\": \"source\", \"Value\": {\"Fn::GetStackOutput\":"
|
||||
+ " {\"StackName\": \"" + OUTPUT_SOURCE + "\", \"OutputName\": \"Out\"}}}],"
|
||||
+ " \"LogGroupName\": {\"Fn::If\": [\"Named\", \"repl-if-output\","
|
||||
+ " {\"Ref\": \"AWS::NoValue\"}]}}}}}",
|
||||
"Subject", "False", false, stack -> createOutputSource()),
|
||||
new Row("deployed parameter renamed, same value",
|
||||
locationStack(stringParameter("NameA", HOSTED), "", REF_A, "d"),
|
||||
locationStack(stringParameter("NameB", HOSTED), "", REF_B, "e"),
|
||||
@@ -193,6 +232,7 @@ class CfnReplacementIntegrationTest {
|
||||
"Subject", "True", true, null));
|
||||
}
|
||||
|
||||
private static final String OUTPUT_SOURCE = "repl-output-source";
|
||||
private static final String HOSTED = "hosted";
|
||||
private static final String REF_A = "{\"Ref\": \"NameA\"}";
|
||||
private static final String REF_B = "{\"Ref\": \"NameB\"}";
|
||||
@@ -208,6 +248,9 @@ class CfnReplacementIntegrationTest {
|
||||
CloudFormationClient.builder(), "test", Region.US_EAST_1)) {
|
||||
CfnStackWaits.createStack(client, stack, row.before(), "CREATE_COMPLETE");
|
||||
String before = physicalId(client, stack, "Subject");
|
||||
if (row.afterCreate() != null) {
|
||||
row.afterCreate().accept(stack);
|
||||
}
|
||||
|
||||
createUpdateChangeSet(client, stack, "change", row.after());
|
||||
assertEquals(List.of(row.preview()), replacement(client, stack, "change", "Subject"), row.label());
|
||||
@@ -226,6 +269,18 @@ class CfnReplacementIntegrationTest {
|
||||
}
|
||||
} finally {
|
||||
CfnStackWaits.deleteStack(stack);
|
||||
if (row.afterCreate() != null) {
|
||||
CfnStackWaits.deleteStack(OUTPUT_SOURCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void createOutputSource() {
|
||||
try (CloudFormationClient client = AwsTestClients.create(
|
||||
CloudFormationClient.builder(), "test", Region.US_EAST_1)) {
|
||||
CfnStackWaits.createStack(client, OUTPUT_SOURCE, "{\"Resources\": {\"Source\": {\"Type\":"
|
||||
+ " \"AWS::SSM::Parameter\", \"Properties\": {\"Type\": \"String\", \"Value\": \"v\"}}},"
|
||||
+ " \"Outputs\": {\"Out\": {\"Value\": \"output-value\"}}}", "CREATE_COMPLETE");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -19,6 +19,7 @@ import java.time.Duration;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
class CloudFormationSesConfigurationSetIntegrationTest {
|
||||
@@ -97,11 +98,20 @@ class CloudFormationSesConfigurationSetIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void addingTheExistingGeneratedNameRollsBackAfterADependentResourceFails() {
|
||||
void addingTheExistingGeneratedNameIsRefusedAndRollsBack() {
|
||||
String generated = createUnnamedConfigurationSet();
|
||||
updateWithDependentFailure(generated);
|
||||
String updatedTemplate = """
|
||||
{
|
||||
"Resources": {
|
||||
"ConfigurationSet": {"Type": "AWS::SES::ConfigurationSet", "Properties": {"Name": "%s"}}
|
||||
},
|
||||
"Outputs": {"ConfigurationSetRef": {"Value": {"Ref": "ConfigurationSet"}}}
|
||||
}
|
||||
""".formatted(generated);
|
||||
cfn.updateStack(request -> request.stackName(stackName).templateBody(updatedTemplate));
|
||||
|
||||
Stack rolledBack = CfnStackWaits.awaitStatus(cfn, stackName, "UPDATE_ROLLBACK_COMPLETE");
|
||||
assertTrue(CfnStackWaits.failedResourceReason(stackName).contains("custom-named resource requires"));
|
||||
assertEquals(generated, rolledBack.outputs().getFirst().outputValue());
|
||||
assertEquals(generated, configurationSets.get(generated, "us-east-1").getName());
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,8 +16,10 @@ class PropertyChangesReplacementTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void aChangedOrDroppedCreateOnlyPropertyReplaces() throws Exception {
|
||||
void aChangedAddedOrDroppedCreateOnlyPropertyReplaces() throws Exception {
|
||||
assertTrue(between("{\"Name\":\"a.example.\"}", "{\"Name\":\"b.example.\"}").requiresReplacement());
|
||||
assertTrue(between("{\"Name\":\"a.example.\"}",
|
||||
"{\"Name\":\"a.example.\",\"DelegationSetId\":\"N1\"}").requiresReplacement());
|
||||
assertTrue(between("{\"Name\":\"a.example.\",\"DelegationSetId\":\"N1\"}",
|
||||
"{\"Name\":\"a.example.\"}").requiresReplacement());
|
||||
assertTrue(PropertyChanges.between(TYPE, true, MAPPER.readTree("{\"Name\":\"a.example.\"}"), null)
|
||||
@@ -25,9 +27,7 @@ class PropertyChangesReplacementTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAddedOrNonCreateOnlyChangeDoesNotReplace() throws Exception {
|
||||
assertFalse(between("{\"Name\":\"a.example.\"}",
|
||||
"{\"Name\":\"a.example.\",\"DelegationSetId\":\"N1\"}").requiresReplacement());
|
||||
void aNonCreateOnlyChangeDoesNotReplace() throws Exception {
|
||||
assertFalse(between("{\"Name\":\"a.example.\",\"HostedZoneConfig\":{\"Comment\":\"x\"}}",
|
||||
"{\"Name\":\"a.example.\",\"HostedZoneConfig\":{\"Comment\":\"y\"}}").requiresReplacement());
|
||||
}
|
||||
|
||||
+5
-5
@@ -608,17 +608,17 @@ class SesCfnProvisionerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void declaringTheExistingGeneratedNameNeedsNoReplacementOrRollbackWork() throws Exception {
|
||||
void declaringTheExistingGeneratedNameIsACustomNameThatCannotBeReplaced() throws Exception {
|
||||
StackResource resource = configurationSetResource(null);
|
||||
JsonNode previous = props("{}");
|
||||
provisioner.provision(resource, previous, context(null));
|
||||
String generated = resource.getPhysicalId();
|
||||
|
||||
provisioner.provision(resource, props("{\"Name\":\"" + generated + "\"}"),
|
||||
configurationSetUpdateContext(generated, previous));
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> provisioner.provision(resource, props("{\"Name\":\"" + generated + "\"}"),
|
||||
configurationSetUpdateContext(generated, previous)));
|
||||
|
||||
assertFalse(provisioner.hasReplacementUpdate(resource));
|
||||
assertTrue(provisioner.rollbackUpdate(resource));
|
||||
assertTrue(error.getMessage().contains("custom-named resource requires replacing"));
|
||||
assertEquals(generated, resource.getPhysicalId());
|
||||
verify(ses, never()).deleteConfigurationSet(any(), any());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user