mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(cloudformation): store stack policies and return them (#7552)
* fix(cloudformation): store stack policies and return them * test(cloudformation): remove the stack policy test bucket after use * fix(cloudformation): apply a stack policy with its stack operation UpdateStack now stores its policy when the update commits, before UPDATE_COMPLETE is published, and CreateStack when execution starts. A policy-only update no longer leaves its change set FAILED. SetStackPolicy checks the stack state again under the stack lock after reading a StackPolicyURL. * fix(cloudformation): apply a creation policy when the create is claimed * fix(cloudformation): keep a rejected policy-only update executable * fix(cloudformation): assign a stack policy when its change set is created * test(cloudformation): stop the stack policy test's executor * test(cloudformation): round-trip stack policies through persistent storage * test(cloudformation): build the stack policy requests on CfnRequests * test(cloudformation): construct CloudFormationService through one shared fixture * fix(cloudformation): refuse a missing or malformed StackName in the stack policy actions SetStackPolicy and GetStackPolicy looked a missing StackName up as the stack named "null". Both now validate StackName first, as AWS does, with the checks ContinueUpdateRollback already applies.
This commit is contained in:
1 parent
cf25c9f6db
commit
a19b296f06
13 files changed
+845
-96
No files matched your search
+40
-7
@@ -65,8 +65,8 @@ public class CloudFormationQueryHandler {
|
||||
case "ValidateTemplate" -> validateTemplate(params);
|
||||
case "ListStacks" -> listStacks(params, region);
|
||||
case "ListExports" -> listExports(params, region);
|
||||
case "SetStackPolicy" -> Response.ok(emptyResult("SetStackPolicyResponse")).build();
|
||||
case "GetStackPolicy" -> Response.ok(emptyResult("GetStackPolicyResponse")).build();
|
||||
case "SetStackPolicy" -> setStackPolicy(params, region);
|
||||
case "GetStackPolicy" -> getStackPolicy(params, region);
|
||||
case "DescribeStackResource" -> describeStackResource(params, region);
|
||||
case "DescribeOrganizationsAccess" -> describeOrganizationsAccess();
|
||||
case "ActivateOrganizationsAccess" -> activateOrganizationsAccess();
|
||||
@@ -117,11 +117,13 @@ public class CloudFormationQueryHandler {
|
||||
Map<String, String> parameters = extractParameters(params);
|
||||
List<String> capabilities = extractList(params, "Capabilities.member.");
|
||||
Map<String, String> tags = extractTags(params);
|
||||
String stackPolicy = cfnService.resolveStackPolicy(params.getFirst("StackPolicyBody"),
|
||||
params.getFirst("StackPolicyURL"), " to be applied after stack creation");
|
||||
|
||||
boolean terminationProtection = Boolean.parseBoolean(params.getFirst("EnableTerminationProtection"));
|
||||
ChangeSet initial = cfnService.createChangeSetForCreateStack(stackName, "initial-create",
|
||||
templateBody, templateUrl, parameters, capabilities, tags, region,
|
||||
terminationProtection);
|
||||
terminationProtection, stackPolicy);
|
||||
try {
|
||||
cfnService.executeChangeSet(initial.getStackId(), initial.getChangeSetId(), region);
|
||||
} catch (AwsException e) {
|
||||
@@ -154,13 +156,15 @@ public class CloudFormationQueryHandler {
|
||||
extractParameters(params, cfnService.currentParameters(stackName, region));
|
||||
List<String> capabilities = extractList(params, "Capabilities.member.");
|
||||
Map<String, String> tags = extractTags(params);
|
||||
String stackPolicy = cfnService.resolveStackPolicy(params.getFirst("StackPolicyBody"),
|
||||
params.getFirst("StackPolicyURL"), " to be applied after stack update");
|
||||
|
||||
String changeSetName = "update-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
ChangeSet cs = usePreviousTemplate
|
||||
? cfnService.createChangeSetFromPreviousTemplate(stackName, changeSetName,
|
||||
parameters, capabilities, tags, region)
|
||||
: cfnService.createChangeSet(stackName, changeSetName,
|
||||
"UPDATE", templateBody, templateUrl, parameters, capabilities, tags, region);
|
||||
parameters, capabilities, tags, region, stackPolicy)
|
||||
: cfnService.createChangeSetForUpdateStack(stackName, changeSetName,
|
||||
templateBody, templateUrl, parameters, capabilities, tags, region, stackPolicy);
|
||||
// An update that submits what the stack already has is refused, and leaves no change set
|
||||
// behind, as UpdateStack does on AWS.
|
||||
if (CloudFormationService.NO_CHANGES_REASON.equals(cs.getStatusReason())) {
|
||||
@@ -241,6 +245,35 @@ public class CloudFormationQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// ── SetStackPolicy / GetStackPolicy ─────────────────────────────────────────
|
||||
|
||||
private Response setStackPolicy(MultivaluedMap<String, String> params, String region) {
|
||||
try {
|
||||
cfnService.setStackPolicy(params.getFirst("StackName"), params.getFirst("StackPolicyBody"),
|
||||
params.getFirst("StackPolicyURL"), region);
|
||||
return Response.ok(emptyResult("SetStackPolicyResponse")).type("text/xml").build();
|
||||
} catch (AwsException e) {
|
||||
return xmlError(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private Response getStackPolicy(MultivaluedMap<String, String> params, String region) {
|
||||
try {
|
||||
String policy = cfnService.getStackPolicy(params.getFirst("StackName"), region);
|
||||
String xml = new XmlBuilder()
|
||||
.start("GetStackPolicyResponse", CF_NS)
|
||||
.start("GetStackPolicyResult")
|
||||
.elem("StackPolicyBody", policy)
|
||||
.end("GetStackPolicyResult")
|
||||
.raw(AwsQueryResponse.responseMetadata())
|
||||
.end("GetStackPolicyResponse")
|
||||
.build();
|
||||
return Response.ok(xml).type("text/xml").build();
|
||||
} catch (AwsException e) {
|
||||
return xmlError(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
// ── CreateChangeSet ───────────────────────────────────────────────────────
|
||||
|
||||
private Response createChangeSet(MultivaluedMap<String, String> params, String region) {
|
||||
@@ -264,7 +297,7 @@ public class CloudFormationQueryHandler {
|
||||
// internally, may attach a CREATE change set to a stack still in REVIEW_IN_PROGRESS.
|
||||
ChangeSet cs = usePreviousTemplate
|
||||
? cfnService.createChangeSetFromPreviousTemplate(stackName, changeSetName,
|
||||
parameters, capabilities, tags, region)
|
||||
parameters, capabilities, tags, region, null)
|
||||
: cfnService.createChangeSetForRequest(stackName, changeSetName, changeSetType,
|
||||
templateBody, templateUrl, parameters, capabilities, tags, region);
|
||||
|
||||
|
||||
+179
-22
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -43,6 +44,7 @@ import org.jboss.logging.Logger;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.GeneralSecurityException;
|
||||
@@ -253,6 +255,126 @@ public class CloudFormationService implements ResourceProvider {
|
||||
});
|
||||
}
|
||||
|
||||
// ── Stack policy ──────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Stores a stack's policy (CloudFormation {@code SetStackPolicy}). The checks run in AWS's order:
|
||||
* the stack's name, the policy source, the stack, the stack's state, then the policy itself.
|
||||
*/
|
||||
public void setStackPolicy(String stackName, String body, String url, String region) {
|
||||
validateStackName(stackName);
|
||||
if (isNullOrEmpty(body) && isNullOrEmpty(url)) {
|
||||
// AWS's own spelling.
|
||||
throw new AwsException("ValidationError", "Ether StackPolicyURL or StackPolicyBody must be specified.", 400);
|
||||
}
|
||||
rejectBothPolicySources(body, url);
|
||||
Stack stack = stackForPolicy(stackName, region);
|
||||
refuseStackPolicyIn(stack);
|
||||
String policy = resolveStackPolicy(body, url, "");
|
||||
// Reading a StackPolicyURL takes time, so the state is checked again under the lock an
|
||||
// update or delete claims.
|
||||
stacks.compute(stackKey(ownerAccount(stack), stack.getStackName(), stack.getRegion()), (key, live) -> {
|
||||
refuseStackPolicyIn(stack);
|
||||
if (live != stack) {
|
||||
throw new AwsException("ValidationError", CONTINUE_STACK_MISSING.formatted(stackName), 400);
|
||||
}
|
||||
stack.setStackPolicyBody(policy);
|
||||
// Persisted under the lock, so a delete that completes next cannot be undone by this write.
|
||||
persistStack(stack);
|
||||
return live;
|
||||
});
|
||||
}
|
||||
|
||||
private static void refuseStackPolicyIn(Stack stack) {
|
||||
String status = stack.getStatus();
|
||||
if (refusesUpdate(status) || "DELETE_COMPLETE".equals(status)) {
|
||||
throw new AwsException("ValidationError",
|
||||
"SetStackPolicy cannot be called when stack is in the " + status + " state", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/** The stack's policy as it was submitted, or null when it has none. A deleted stack keeps it. */
|
||||
public String getStackPolicy(String stackName, String region) {
|
||||
validateStackName(stackName);
|
||||
return stackForPolicy(stackName, region).getStackPolicyBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* The policy a request supplies as {@code StackPolicyBody} or, read from S3, as
|
||||
* {@code StackPolicyURL}, or null when it supplies neither. {@code appliedWhen} completes AWS's
|
||||
* message for a policy that is not one. The check is structural: Floci stores a policy but does
|
||||
* not enforce it.
|
||||
*/
|
||||
public String resolveStackPolicy(String body, String url, String appliedWhen) {
|
||||
rejectBothPolicySources(body, url);
|
||||
if (isNullOrEmpty(body) && isNullOrEmpty(url)) {
|
||||
return null;
|
||||
}
|
||||
String policy = isNullOrEmpty(url) ? body : fetchTemplateFromS3(url);
|
||||
if (!isStackPolicy(policy)) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Error validating stack policy" + appliedWhen + ": Invalid stack policy", 400);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
private static void rejectBothPolicySources(String body, String url) {
|
||||
if (!isNullOrEmpty(body) && !isNullOrEmpty(url)) {
|
||||
throw new AwsException("ValidationError", "You cannot specify both StackPolicyURL and StackPolicyBody", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private Stack stackForPolicy(String stackName, String region) {
|
||||
Stack stack = resolveStackForDescribe(stackName, region);
|
||||
if (stack == null) {
|
||||
throw new AwsException("ValidationError", CONTINUE_STACK_MISSING.formatted(stackName), 400);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* A JSON object that is empty or has a {@code Statement}: one statement object or a non-empty
|
||||
* array of them, each with an Allow or Deny {@code Effect} and not both {@code Action} and
|
||||
* {@code NotAction}. These are the shapes AWS refuses as "Invalid stack policy".
|
||||
*/
|
||||
private boolean isStackPolicy(String policy) {
|
||||
JsonNode root;
|
||||
try {
|
||||
root = objectMapper.reader().with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS).readTree(policy);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
if (root == null || !root.isObject()) {
|
||||
return false;
|
||||
}
|
||||
if (root.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
JsonNode statements = root.path("Statement");
|
||||
if (statements.isObject()) {
|
||||
return isPolicyStatement(statements);
|
||||
}
|
||||
if (!statements.isArray() || statements.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (JsonNode statement : statements) {
|
||||
if (!isPolicyStatement(statement)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isPolicyStatement(JsonNode statement) {
|
||||
String effect = statement.path("Effect").asText();
|
||||
return ("Allow".equalsIgnoreCase(effect) || "Deny".equalsIgnoreCase(effect))
|
||||
&& !(statement.has("Action") && statement.has("NotAction"));
|
||||
}
|
||||
|
||||
private static boolean isNullOrEmpty(String value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
|
||||
// ── DescribeStacks ────────────────────────────────────────────────────────
|
||||
|
||||
public List<Stack> describeStacks(String stackName, String region) {
|
||||
@@ -356,7 +478,8 @@ public class CloudFormationService implements ResourceProvider {
|
||||
public ChangeSet createChangeSetFromPreviousTemplate(String stackName, String changeSetName,
|
||||
Map<String, String> parameters,
|
||||
List<String> capabilities,
|
||||
Map<String, String> tags, String region) {
|
||||
Map<String, String> tags, String region,
|
||||
String stackPolicy) {
|
||||
ChangeSet created = null;
|
||||
while (created == null) {
|
||||
Stack stack = resolveStack(stackName, region);
|
||||
@@ -366,7 +489,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
}
|
||||
String previousTemplate = previousTemplateOf(stack);
|
||||
created = createChangeSet(stackName, changeSetName, "UPDATE", previousTemplate, null,
|
||||
parameters, capabilities, tags, region, currentAccount(), false, true, false);
|
||||
parameters, capabilities, tags, region, currentAccount(), false, true, false, stackPolicy);
|
||||
}
|
||||
return created;
|
||||
}
|
||||
@@ -384,17 +507,26 @@ public class CloudFormationService implements ResourceProvider {
|
||||
Map<String, String> parameters, List<String> capabilities,
|
||||
Map<String, String> tags, String region) {
|
||||
return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl,
|
||||
parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false, false);
|
||||
parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false, false, null);
|
||||
}
|
||||
|
||||
public ChangeSet createChangeSetForCreateStack(String stackName, String changeSetName,
|
||||
String templateBody, String templateUrl,
|
||||
Map<String, String> parameters, List<String> capabilities,
|
||||
Map<String, String> tags, String region,
|
||||
boolean enableTerminationProtection) {
|
||||
boolean enableTerminationProtection, String stackPolicy) {
|
||||
return createChangeSet(stackName, changeSetName, "CREATE", templateBody, templateUrl,
|
||||
parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false,
|
||||
enableTerminationProtection);
|
||||
enableTerminationProtection, stackPolicy);
|
||||
}
|
||||
|
||||
public ChangeSet createChangeSetForUpdateStack(String stackName, String changeSetName,
|
||||
String templateBody, String templateUrl,
|
||||
Map<String, String> parameters, List<String> capabilities,
|
||||
Map<String, String> tags, String region, String stackPolicy) {
|
||||
return createChangeSet(stackName, changeSetName, "UPDATE", templateBody, templateUrl,
|
||||
parameters, capabilities, tags, region, regionResolver.getAccountId(), false, false, false,
|
||||
stackPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -418,7 +550,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
Map<String, String> parameters, List<String> capabilities,
|
||||
Map<String, String> tags, String region) {
|
||||
return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl,
|
||||
parameters, capabilities, tags, region, regionResolver.getAccountId(), true, false, false);
|
||||
parameters, capabilities, tags, region, regionResolver.getAccountId(), true, false, false, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,7 +568,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
Map<String, String> parameters, List<String> capabilities,
|
||||
Map<String, String> tags, String region, String accountId) {
|
||||
return createChangeSet(stackName, changeSetName, changeSetType, templateBody, templateUrl,
|
||||
parameters, capabilities, tags, region, accountId, false, false, false);
|
||||
parameters, capabilities, tags, region, accountId, false, false, false, null);
|
||||
}
|
||||
|
||||
private ChangeSet createChangeSet(String stackName, String changeSetName, String changeSetType,
|
||||
@@ -444,7 +576,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
Map<String, String> parameters, List<String> capabilities,
|
||||
Map<String, String> tags, String region, String accountId,
|
||||
boolean attachToReviewInProgressStack, boolean fromPreviousTemplate,
|
||||
boolean enableTerminationProtection) {
|
||||
boolean enableTerminationProtection, String stackPolicy) {
|
||||
String resolvedTemplate = resolveTemplate(templateBody, templateUrl);
|
||||
requireValidTemplate(resolvedTemplate);
|
||||
boolean isCreateType = "CREATE".equalsIgnoreCase(changeSetType);
|
||||
@@ -589,11 +721,14 @@ public class CloudFormationService implements ResourceProvider {
|
||||
cs.setParameters(parameters);
|
||||
cs.setCapabilities(capabilities);
|
||||
cs.setTags(tags);
|
||||
cs.setStackPolicyBody(stackPolicy);
|
||||
// A new stack policy alone is still an update.
|
||||
boolean newPolicy = stackPolicy != null && !stackPolicy.equals(target.getStackPolicyBody());
|
||||
if (samTransformFailureReason != null) {
|
||||
cs.setStatus("FAILED");
|
||||
cs.setExecutionStatus("UNAVAILABLE");
|
||||
cs.setStatusReason(samTransformFailureReason);
|
||||
} else if (unchanged[0]) {
|
||||
} else if (unchanged[0] && !newPolicy) {
|
||||
cs.setStatus("FAILED");
|
||||
cs.setExecutionStatus("UNAVAILABLE");
|
||||
cs.setStatusReason(NO_CHANGES_REASON);
|
||||
@@ -1226,7 +1361,8 @@ public class CloudFormationService implements ResourceProvider {
|
||||
private record StackMutationSnapshot(String status, Instant lastUpdatedTime,
|
||||
List<StackEvent> events,
|
||||
Map<String, ChangeSet> changeSets,
|
||||
Map<ChangeSet, ChangeSetState> changeSetStates) {}
|
||||
Map<ChangeSet, ChangeSetState> changeSetStates,
|
||||
String stackPolicyBody) {}
|
||||
|
||||
// compute() holds the stack's per-key lock for the whole claim, so only one racing execution can win.
|
||||
private Future<?> claimAndSubmitExecution(String stackNameOrArn, String changeSetName, String region,
|
||||
@@ -1273,6 +1409,9 @@ public class CloudFormationService implements ResourceProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isCreate && cs.getStackPolicyBody() != null) {
|
||||
existing.setStackPolicyBody(cs.getStackPolicyBody());
|
||||
}
|
||||
existing.setStatus(isCreate ? "CREATE_IN_PROGRESS" : "UPDATE_IN_PROGRESS");
|
||||
existing.setLastUpdatedTime(now());
|
||||
addEvent(existing, existing.getStackName(), existing.getStackId(),
|
||||
@@ -1315,7 +1454,8 @@ public class CloudFormationService implements ResourceProvider {
|
||||
|
||||
return submitOperation(() -> RequestScopes.runAs(accountId, region, () -> {
|
||||
try {
|
||||
executeTemplate(stack, templateBody, params, cs.getTags(), claimed.isCreate(), region, accountId);
|
||||
executeTemplate(stack, templateBody, params, cs.getTags(), claimed.isCreate(), region, accountId,
|
||||
cs.getStackPolicyBody());
|
||||
String status = stack.getStatus();
|
||||
cs.setExecutionStatus(status != null && (status.contains("ROLLBACK") || status.endsWith("_FAILED"))
|
||||
? "EXECUTE_FAILED" : "EXECUTE_COMPLETE");
|
||||
@@ -1563,6 +1703,26 @@ public class CloudFormationService implements ResourceProvider {
|
||||
* {@code ValidationError}, with AWS's texts. A skip has no length limit.
|
||||
*/
|
||||
private static void validateContinueUpdateRollback(String stackNameOrArn, List<String> resourcesToSkip) {
|
||||
List<String> violations = stackNameViolations(stackNameOrArn);
|
||||
if (resourcesToSkip.stream().anyMatch(skip -> !RESOURCE_TO_SKIP.matcher(skip).matches())) {
|
||||
violations.add("Value '" + resourcesToSkip + "' at 'resourcesToSkip' failed to satisfy constraint:"
|
||||
+ " Member must satisfy constraint: [Member must satisfy regular expression pattern: "
|
||||
+ RESOURCE_TO_SKIP.pattern() + "]");
|
||||
}
|
||||
if (!violations.isEmpty()) {
|
||||
throw SmithyValidationErrors.validationError(violations);
|
||||
}
|
||||
}
|
||||
|
||||
/** Refuses a {@code StackName} AWS's model refuses, before anything else in the request is checked. */
|
||||
private static void validateStackName(String stackNameOrArn) {
|
||||
List<String> violations = stackNameViolations(stackNameOrArn);
|
||||
if (!violations.isEmpty()) {
|
||||
throw SmithyValidationErrors.validationError(violations);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> stackNameViolations(String stackNameOrArn) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
if (stackNameOrArn == null) {
|
||||
violations.add(SmithyValidationErrors.notNull("stackName"));
|
||||
@@ -1576,14 +1736,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
+ " Member must satisfy regular expression pattern: " + STACK_NAME.pattern());
|
||||
}
|
||||
}
|
||||
if (resourcesToSkip.stream().anyMatch(skip -> !RESOURCE_TO_SKIP.matcher(skip).matches())) {
|
||||
violations.add("Value '" + resourcesToSkip + "' at 'resourcesToSkip' failed to satisfy constraint:"
|
||||
+ " Member must satisfy constraint: [Member must satisfy regular expression pattern: "
|
||||
+ RESOURCE_TO_SKIP.pattern() + "]");
|
||||
}
|
||||
if (!violations.isEmpty()) {
|
||||
throw SmithyValidationErrors.validationError(violations);
|
||||
}
|
||||
return violations;
|
||||
}
|
||||
|
||||
private StackMutationSnapshot snapshot(Stack stack) {
|
||||
@@ -1592,7 +1745,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
states.put(changeSet, new ChangeSetState(changeSet.getStatus(), changeSet.getExecutionStatus()));
|
||||
}
|
||||
return new StackMutationSnapshot(stack.getStatus(), stack.getLastUpdatedTime(),
|
||||
stack.eventsSnapshot(), stack.changeSetsSnapshot(), states);
|
||||
stack.eventsSnapshot(), stack.changeSetsSnapshot(), states, stack.getStackPolicyBody());
|
||||
}
|
||||
|
||||
private void restore(Stack stack, StackMutationSnapshot snapshot) {
|
||||
@@ -1601,6 +1754,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
}
|
||||
stack.setStatus(snapshot.status());
|
||||
stack.setLastUpdatedTime(snapshot.lastUpdatedTime());
|
||||
stack.setStackPolicyBody(snapshot.stackPolicyBody());
|
||||
stack.setEvents(new ArrayList<>(snapshot.events()));
|
||||
stack.setChangeSets(new LinkedHashMap<>(snapshot.changeSets()));
|
||||
snapshot.changeSetStates().forEach((changeSet, state) -> {
|
||||
@@ -2073,7 +2227,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) {
|
||||
boolean isCreate, String region, String accountId, String stackPolicy) {
|
||||
Map<String, String> previousTags = stack.tagsSnapshot();
|
||||
Map<String, String> operationTags = tags == null ? previousTags : new LinkedHashMap<>(tags);
|
||||
boolean stackTagsChanged = !operationTags.equals(previousTags);
|
||||
@@ -2432,6 +2586,9 @@ public class CloudFormationService implements ResourceProvider {
|
||||
|
||||
if (!isCreate) {
|
||||
updateCommitted = true;
|
||||
if (stackPolicy != null) {
|
||||
stack.setStackPolicyBody(stackPolicy);
|
||||
}
|
||||
stack.replaceTags(operationTags);
|
||||
stack.getResources().values().forEach(resource -> resource.getAttributes()
|
||||
.remove(CfnRollback.NESTED_STACK_UPDATE_SNAPSHOT_ATTR));
|
||||
@@ -4474,7 +4631,7 @@ public class CloudFormationService implements ResourceProvider {
|
||||
savedChildDeployment(childStack, region, accountId).toString());
|
||||
}
|
||||
|
||||
executeTemplate(childStack, childTemplate, childParams, childTags, childCreate, region, accountId);
|
||||
executeTemplate(childStack, childTemplate, childParams, childTags, childCreate, region, accountId, null);
|
||||
|
||||
resource.setPhysicalId(childStack.getStackId());
|
||||
resource.getAttributes().put("Arn", childStack.getStackId());
|
||||
|
||||
@@ -24,6 +24,9 @@ public class ChangeSet {
|
||||
private Map<String, String> tags;
|
||||
private String changeSetType; // CREATE or UPDATE
|
||||
private Instant creationTime = Instant.now();
|
||||
// AWS change sets carry no stack policy; this is the policy a CreateStack or UpdateStack
|
||||
// applies with its change set.
|
||||
private String stackPolicyBody;
|
||||
|
||||
public String getChangeSetId() { return changeSetId; }
|
||||
public void setChangeSetId(String changeSetId) { this.changeSetId = changeSetId; }
|
||||
@@ -51,4 +54,6 @@ public class ChangeSet {
|
||||
public void setChangeSetType(String changeSetType) { this.changeSetType = changeSetType; }
|
||||
public Instant getCreationTime() { return creationTime; }
|
||||
public void setCreationTime(Instant creationTime) { this.creationTime = creationTime; }
|
||||
public String getStackPolicyBody() { return stackPolicyBody; }
|
||||
public void setStackPolicyBody(String stackPolicyBody) { this.stackPolicyBody = stackPolicyBody; }
|
||||
}
|
||||
@@ -72,6 +72,7 @@ public class Stack {
|
||||
private Map<String, ChangeSet> changeSets = orderedMap();
|
||||
private Map<String, String> tags = orderedMap();
|
||||
private boolean enableTerminationProtection = false;
|
||||
private volatile String stackPolicyBody;
|
||||
/**
|
||||
* Set when an update rollback fails, and kept until a rollback completes or the stack is
|
||||
* deleted: the state from before the failed update, and the logical ids whose rollback has not
|
||||
@@ -227,6 +228,8 @@ public class Stack {
|
||||
}
|
||||
public boolean isEnableTerminationProtection() { return enableTerminationProtection; }
|
||||
public void setEnableTerminationProtection(boolean enableTerminationProtection) { this.enableTerminationProtection = enableTerminationProtection; }
|
||||
public String getStackPolicyBody() { return stackPolicyBody; }
|
||||
public void setStackPolicyBody(String stackPolicyBody) { this.stackPolicyBody = stackPolicyBody; }
|
||||
public StackUpdateSnapshot getUpdateRollbackSnapshot() { return updateRollbackSnapshot; }
|
||||
public void setUpdateRollbackSnapshot(StackUpdateSnapshot updateRollbackSnapshot) { this.updateRollbackSnapshot = updateRollbackSnapshot; }
|
||||
public List<String> getUpdateRollbackResourceIds() { return updateRollbackResourceIds; }
|
||||
|
||||
Reference in new issue
Block a user