mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(cloudformation): support UpdateTerminationProtection (#1692)
* feat(cloudformation): support UpdateTerminationProtection CDK bootstrap calls UpdateTerminationProtection on the CDKToolkit stack; Floci returned UnknownAction. Add it: a boolean enableTerminationProtection on Stack, a CloudFormationService.updateTerminationProtection(stackName, enabled, region) that sets and persists it, a handler returning the UpdateTerminationProtectionResult/StackId envelope, and the flag echoed as <EnableTerminationProtection> in DescribeStacks. Register the action in AwsQueryController's CloudFormation action set so the Query-protocol POST routes to CloudFormation instead of falling through. Adds an integration test toggling the flag and asserting it round-trips through DescribeStacks. * docs: regenerate action tables
This commit is contained in:
1 parent
dd566857ef
commit
4a16266f48
6 files changed
+179
-8
No files matched your search
@@ -351,7 +351,7 @@ public class AwsQueryController {
|
||||
);
|
||||
|
||||
private static final Set<String> CLOUDFORMATION_ACTIONS = Set.of(
|
||||
"CreateStack", "DeleteStack", "UpdateStack", "DescribeStacks",
|
||||
"CreateStack", "DeleteStack", "UpdateStack", "DescribeStacks", "UpdateTerminationProtection",
|
||||
"ListStacks", "ListExports", "GetTemplate", "ValidateTemplate",
|
||||
"CreateChangeSet", "DeleteChangeSet", "DescribeChangeSet", "ExecuteChangeSet", "ListChangeSets",
|
||||
"DescribeStackEvents", "DescribeStackResources", "ListStackResources", "DescribeStackResource",
|
||||
|
||||
+39
-7
@@ -49,6 +49,7 @@ public class CloudFormationQueryHandler {
|
||||
case "CreateStack" -> createStack(params, region);
|
||||
case "UpdateStack" -> updateStack(params, region);
|
||||
case "DeleteStack" -> deleteStack(params, region);
|
||||
case "UpdateTerminationProtection" -> updateTerminationProtection(params, region);
|
||||
case "CreateChangeSet" -> createChangeSet(params, region);
|
||||
case "DescribeChangeSet" -> describeChangeSet(params, region);
|
||||
case "ExecuteChangeSet" -> executeChangeSet(params, region);
|
||||
@@ -115,6 +116,11 @@ public class CloudFormationQueryHandler {
|
||||
templateBody, templateUrl, parameters, capabilities, tags, region);
|
||||
awaitExecution(cfnService.executeChangeSet(stackName, "initial-create", region));
|
||||
|
||||
if (Boolean.parseBoolean(params.getFirst("EnableTerminationProtection"))) {
|
||||
// CreateStackInput carries the same member; honor it so the stack is created protected.
|
||||
cfnService.updateTerminationProtection(stackName, true, region);
|
||||
}
|
||||
|
||||
Stack stack = cfnService.describeStacks(stackName, region).get(0);
|
||||
String xml = new XmlBuilder()
|
||||
.start("CreateStackResponse", CF_NS)
|
||||
@@ -156,13 +162,38 @@ public class CloudFormationQueryHandler {
|
||||
|
||||
private Response deleteStack(MultivaluedMap<String, String> params, String region) {
|
||||
String stackName = params.getFirst("StackName");
|
||||
cfnService.deleteStack(stackName, region);
|
||||
String xml = new XmlBuilder()
|
||||
.start("DeleteStackResponse", CF_NS)
|
||||
.raw(AwsQueryResponse.responseMetadata())
|
||||
.end("DeleteStackResponse")
|
||||
.build();
|
||||
return Response.ok(xml).type("text/xml").build();
|
||||
try {
|
||||
cfnService.deleteStack(stackName, region);
|
||||
String xml = new XmlBuilder()
|
||||
.start("DeleteStackResponse", CF_NS)
|
||||
.raw(AwsQueryResponse.responseMetadata())
|
||||
.end("DeleteStackResponse")
|
||||
.build();
|
||||
return Response.ok(xml).type("text/xml").build();
|
||||
} catch (AwsException e) {
|
||||
return xmlError(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
// ── UpdateTerminationProtection ─────────────────────────────────────────────
|
||||
|
||||
private Response updateTerminationProtection(MultivaluedMap<String, String> params, String region) {
|
||||
String stackName = params.getFirst("StackName");
|
||||
boolean enabled = Boolean.parseBoolean(params.getFirst("EnableTerminationProtection"));
|
||||
try {
|
||||
Stack stack = cfnService.updateTerminationProtection(stackName, enabled, region);
|
||||
String xml = new XmlBuilder()
|
||||
.start("UpdateTerminationProtectionResponse", CF_NS)
|
||||
.start("UpdateTerminationProtectionResult")
|
||||
.elem("StackId", stack.getStackId())
|
||||
.end("UpdateTerminationProtectionResult")
|
||||
.raw(AwsQueryResponse.responseMetadata())
|
||||
.end("UpdateTerminationProtectionResponse")
|
||||
.build();
|
||||
return Response.ok(xml).type("text/xml").build();
|
||||
} catch (AwsException e) {
|
||||
return xmlError(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
// ── CreateChangeSet ───────────────────────────────────────────────────────
|
||||
@@ -471,6 +502,7 @@ public class CloudFormationQueryHandler {
|
||||
.elem("StackId", s.getStackId())
|
||||
.elem("StackName", s.getStackName())
|
||||
.elem("StackStatus", s.getStatus())
|
||||
.elem("EnableTerminationProtection", String.valueOf(s.isEnableTerminationProtection()))
|
||||
.elem("CreationTime", ISO.format(s.getCreationTime()));
|
||||
if (s.getLastUpdatedTime() != null) {
|
||||
xml.elem("LastUpdatedTime", ISO.format(s.getLastUpdatedTime()));
|
||||
|
||||
+17
@@ -112,6 +112,17 @@ public class CloudFormationService {
|
||||
stackBackend.deleteForAccount(storageAccount, key(stackName, region));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a stack's termination protection (CloudFormation {@code UpdateTerminationProtection}).
|
||||
* Returns the stack so the caller can echo its {@code StackId}.
|
||||
*/
|
||||
public Stack updateTerminationProtection(String stackName, boolean enabled, String region) {
|
||||
Stack stack = getStackOrThrow(stackName, region);
|
||||
stack.setEnableTerminationProtection(enabled);
|
||||
persistStack(stack);
|
||||
return stack;
|
||||
}
|
||||
|
||||
// ── DescribeStacks ────────────────────────────────────────────────────────
|
||||
|
||||
public List<Stack> describeStacks(String stackName, String region) {
|
||||
@@ -290,6 +301,12 @@ public class CloudFormationService {
|
||||
if (stack == null) {
|
||||
return CompletableFuture.completedFuture(null); // Already gone — no-op
|
||||
}
|
||||
if (stack.isEnableTerminationProtection()) {
|
||||
// Real AWS rejects deletion of a protected stack and leaves it unchanged.
|
||||
throw new AwsException("ValidationError",
|
||||
"Stack [" + stack.getStackId()
|
||||
+ "] cannot be deleted while TerminationProtection is enabled", 400);
|
||||
}
|
||||
stack.setStatus("DELETE_IN_PROGRESS");
|
||||
addEvent(stack, stack.getStackName(), stack.getStackId(),
|
||||
"AWS::CloudFormation::Stack", "DELETE_IN_PROGRESS", null);
|
||||
|
||||
@@ -27,6 +27,7 @@ public class Stack {
|
||||
private List<StackEvent> events = new ArrayList<>();
|
||||
private Map<String, ChangeSet> changeSets = new LinkedHashMap<>();
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private boolean enableTerminationProtection = false;
|
||||
|
||||
public String getStackId() { return stackId; }
|
||||
public void setStackId(String stackId) { this.stackId = stackId; }
|
||||
@@ -62,4 +63,6 @@ public class Stack {
|
||||
public void setChangeSets(Map<String, ChangeSet> changeSets) { this.changeSets = changeSets; }
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
public boolean isEnableTerminationProtection() { return enableTerminationProtection; }
|
||||
public void setEnableTerminationProtection(boolean enableTerminationProtection) { this.enableTerminationProtection = enableTerminationProtection; }
|
||||
}
|
||||
Reference in new issue
Block a user