mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(cloudformation): apply stack tags during updates (#5031)
* fix(cloudformation): apply stack tags during updates * test(cloudformation): cover tags-only and failed stack updates * fix(cloudformation): distinguish empty tags from omitted tags * fix(cloudformation): reject implicit CREATE with previous template * test(cloudformation): validate stack tag updates with AWS SDK * test(cloudformation): fail on SDK cleanup errors * fix(cloudformation): allow previous template with omitted type
This commit is contained in:
1 parent
523003972e
commit
a6df1dbb12
6 files changed
+280
-5
No files matched your search
+6
-3
@@ -150,13 +150,14 @@ public class CloudFormationQueryHandler {
|
||||
Map<String, String> parameters =
|
||||
extractParameters(params, cfnService.currentParameters(stackName, region));
|
||||
List<String> capabilities = extractList(params, "Capabilities.member.");
|
||||
Map<String, String> tags = extractTags(params);
|
||||
|
||||
String changeSetName = "update-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
ChangeSet cs = usePreviousTemplate
|
||||
? cfnService.createChangeSetFromPreviousTemplate(stackName, changeSetName,
|
||||
parameters, capabilities, Map.of(), region)
|
||||
parameters, capabilities, tags, region)
|
||||
: cfnService.createChangeSet(stackName, changeSetName,
|
||||
"UPDATE", templateBody, templateUrl, parameters, capabilities, Map.of(), region);
|
||||
"UPDATE", templateBody, templateUrl, parameters, capabilities, tags, region);
|
||||
awaitExecution(cfnService.executeChangeSet(stackName, cs.getChangeSetName(), region));
|
||||
|
||||
Stack stack = cfnService.describeStacks(stackName, region).get(0);
|
||||
@@ -723,7 +724,9 @@ public class CloudFormationQueryHandler {
|
||||
result.put(key, value != null ? value : "");
|
||||
i++;
|
||||
}
|
||||
return result;
|
||||
boolean supplied = params.keySet().stream().anyMatch(name ->
|
||||
"Tags".equals(name) || "Tags.member".equals(name) || name.startsWith("Tags.member."));
|
||||
return supplied ? result : null;
|
||||
}
|
||||
|
||||
private List<String> extractList(MultivaluedMap<String, String> params, String prefix) {
|
||||
|
||||
+7
-2
@@ -441,6 +441,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
cs.setTemplateBody(resolvedTemplate);
|
||||
cs.setParameters(parameters);
|
||||
cs.setCapabilities(capabilities);
|
||||
cs.setTags(tags);
|
||||
if (samTransformFailureReason != null) {
|
||||
cs.setStatus("FAILED");
|
||||
cs.setExecutionStatus("UNAVAILABLE");
|
||||
@@ -940,7 +941,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
Map<String, String> params = cs.getParameters() != null ? cs.getParameters() : Map.of();
|
||||
|
||||
return submitOperation(() -> RequestScopes.runAs(accountId, region, () -> {
|
||||
executeTemplate(stack, templateBody, params, isCreate, region, accountId);
|
||||
executeTemplate(stack, templateBody, params, cs.getTags(), isCreate, region, accountId);
|
||||
String status = stack.getStatus();
|
||||
cs.setExecutionStatus(status != null && (status.contains("ROLLBACK") || status.endsWith("_FAILED"))
|
||||
? "EXECUTE_FAILED" : "EXECUTE_COMPLETE");
|
||||
@@ -1404,6 +1405,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
}
|
||||
|
||||
private void executeTemplate(Stack stack, String templateBody, Map<String, String> params,
|
||||
Map<String, String> tags,
|
||||
boolean isCreate, String region, String accountId) {
|
||||
StackUpdateSnapshot previousState = snapshotForUpdate(stack);
|
||||
boolean updateCommitted = false;
|
||||
@@ -1681,6 +1683,9 @@ public class CloudFormationService implements ResourceProvider {
|
||||
|
||||
if (!isCreate) {
|
||||
updateCommitted = true;
|
||||
if (tags != null) {
|
||||
stack.replaceTags(tags);
|
||||
}
|
||||
if (hasReplacementUpdates(stack) || hasRemovedOrConditionFalseResources(stack, resources, conditions)) {
|
||||
stack.setStatus("UPDATE_COMPLETE_CLEANUP_IN_PROGRESS");
|
||||
stack.setLastUpdatedTime(now());
|
||||
@@ -2803,7 +2808,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
childParams.put(e.getKey(), engine.resolve(e.getValue())));
|
||||
}
|
||||
|
||||
executeTemplate(childStack, childTemplate, childParams, childCreate, region, accountId);
|
||||
executeTemplate(childStack, childTemplate, childParams, null, childCreate, region, accountId);
|
||||
|
||||
resource.setPhysicalId(childStack.getStackId());
|
||||
resource.getAttributes().put("Arn", childStack.getStackId());
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -20,6 +21,7 @@ public class ChangeSet {
|
||||
private String templateBody;
|
||||
private Map<String, String> parameters;
|
||||
private List<String> capabilities;
|
||||
private Map<String, String> tags;
|
||||
private String changeSetType; // CREATE or UPDATE
|
||||
private Instant creationTime = Instant.now();
|
||||
|
||||
@@ -43,6 +45,8 @@ public class ChangeSet {
|
||||
public void setParameters(Map<String, String> parameters) { this.parameters = parameters; }
|
||||
public List<String> getCapabilities() { return capabilities; }
|
||||
public void setCapabilities(List<String> capabilities) { this.capabilities = capabilities; }
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags == null ? null : new LinkedHashMap<>(tags); }
|
||||
public String getChangeSetType() { return changeSetType; }
|
||||
public void setChangeSetType(String changeSetType) { this.changeSetType = changeSetType; }
|
||||
public Instant getCreationTime() { return creationTime; }
|
||||
|
||||
@@ -158,6 +158,7 @@ public class Stack {
|
||||
public void replaceOutputs(Map<String, String> source) { replace(outputs, source); }
|
||||
public void replaceExports(Map<String, String> source) { replace(exports, source); }
|
||||
public void replaceOutputExportNames(Map<String, String> source) { replace(outputExportNames, source); }
|
||||
public void replaceTags(Map<String, String> source) { replace(tags, source); }
|
||||
|
||||
private static <V> void replace(Map<String, V> target, Map<String, V> source) {
|
||||
synchronized (target) {
|
||||
|
||||
Reference in new issue
Block a user