Skip to content

Commit 1160e22

Browse files
committed
Add :change-set option to stack component
- Add `:change-set` option to `salmon.cloudformation/stack`. This allows providing a change set as the source of stack updates instead of providing parameters and a template.
1 parent 919d2cf commit 1160e22

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
- Add `salmon.cloudformation/change-set` to create and manage change sets
44
for cloudformation stacks. This makes it easier to analyze what
55
changes will be made to a stack.
6+
- Add `:change-set` option to `salmon.cloudformation/stack`. This allows
7+
providing a change set as the source of stack updates instead of
8+
providing parameters and a template.
69

710
## v0.21.0 (2025-02-10)
811

src/salmon/cloudformation.clj

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@
248248
:StackName StackId}}))
249249
(update-stack! client request StackId)))))
250250

251+
(defn- execute-change-set! [client stack-name {:keys [changes id]}]
252+
(when (seq changes)
253+
; This op only returns {}
254+
(u/invoke! client
255+
{:op :ExecuteChangeSet
256+
:request
257+
{:ChangeSetName id
258+
:StackName stack-name}})))
259+
251260
(defn- outputs-map-raw [outputs-seq]
252261
(reduce
253262
(fn [m {:keys [OutputKey] :as output}]
@@ -314,14 +323,24 @@
314323

315324
(defn- start-stack! [{::ds/keys [config instance system]
316325
:as signal}]
317-
(let [{:keys [name region template]} config
318-
{:keys [client]} instance
326+
(let [{:keys [change-set name region template]} config
327+
{inst-client :client} instance
328+
client (or inst-client
329+
(:client config)
330+
(aws/client {:api :cloudformation :region region}))
319331
schema (-> system ::ds/component-def :schema)]
320-
(if client
332+
(cond
333+
inst-client
321334
instance
322-
(let [_ (validate! signal schema template)
323-
client (or (:client config)
324-
(aws/client {:api :cloudformation :region region}))]
335+
336+
change-set
337+
(let [{:keys [stack-id]} change-set
338+
r (execute-change-set! client name change-set)]
339+
(wait-until-complete! stack-id client)
340+
(stack-instance client name stack-id))
341+
342+
:else
343+
(do (validate! signal schema template)
325344
(loop [[r updated?] (cou-stack! client signal (:json (template-data :template template :validate? false)))]
326345
(cond
327346
(some-> r u/aws-error-message in-progress-error-message?)
@@ -336,7 +355,7 @@
336355
(do
337356
(when updated?
338357
(wait-until-complete! name client :error-on-rollback? true))
339-
(stack-instance client (:name config) r))))))))
358+
(stack-instance client name r))))))))
340359

341360
(defn- stop!
342361
"Stops a [[change-set]], [[stack]], or [[stack-properties]]."
@@ -369,6 +388,11 @@
369388
\"CAPABILITY_IAM\"
370389
\"CAPABILITY_NAMED_IAM\"}
371390
391+
:change-set
392+
A reference to a [[change-set]] component.
393+
If this is provided, the :capabilities, :parameters,
394+
and :template options for the stack are ignored.
395+
372396
:client
373397
An AWS client as produced by
374398
`cognitect.aws.client.api/client`
@@ -406,10 +430,10 @@
406430
:salmon/early-validate
407431
(fn [{{::ds/keys [component-def]} ::ds/system
408432
:as signal}]
409-
(validate! signal
410-
(:salmon/early-schema component-def)
411-
(-> component-def ::ds/config :template)
412-
:pre? true))
433+
(let [{{:keys [change-set template]} ::ds/config
434+
:salmon/keys [early-schema]} component-def]
435+
(when-not change-set
436+
(validate! signal early-schema template :pre? true))))
413437
:schema stack-schema})
414438

415439
(defn- get-stack-properties!

0 commit comments

Comments
 (0)