Skip to content

Commit 7c3bae2

Browse files
committed
Check termination protection before deleting objs
We don't want to delete S3 objects and then fail the actual stack delete because termination protection is enabled. Just ignore stacks with termination protection.
1 parent 05a83e9 commit 7c3bae2

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/salmon/cleanup.clj

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,19 @@
122122
(log/info "Deleted bucket" bucket-name)))))
123123

124124
(defn- full-delete-stack! [client stack-id region]
125-
(doseq [{:keys [PhysicalResourceId :ResourceStatus ResourceType]}
126-
#__ (->> {:op :ListStackResources
127-
:request {:StackName stack-id}}
128-
(u/pages-seq client)
129-
(mapcat :StackResourceSummaries))
130-
:when (not (#{"CREATE_FAILED" "DELETE_COMPLETE"} ResourceStatus))]
131-
(case ResourceType
132-
"AWS::S3::Bucket" (full-delete-bucket! PhysicalResourceId region)
133-
nil))
125+
(when (->> (aws/invoke client
126+
{:op :DescribeStacks
127+
:StackName stack-id})
128+
:Stacks first :EnableTerminationProtection false?)
129+
(doseq [{:keys [PhysicalResourceId :ResourceStatus ResourceType]}
130+
#__ (->> {:op :ListStackResources
131+
:request {:StackName stack-id}}
132+
(u/pages-seq client)
133+
(mapcat :StackResourceSummaries))
134+
:when (not (#{"CREATE_FAILED" "DELETE_COMPLETE"} ResourceStatus))]
135+
(case ResourceType
136+
"AWS::S3::Bucket" (full-delete-bucket! PhysicalResourceId region)
137+
nil)))
134138
(let [r (aws/invoke client
135139
{:op :DeleteStack
136140
:request {:StackName stack-id}})]

0 commit comments

Comments
 (0)