@@ -175,9 +175,8 @@ func (s sdk) CreateStack(ctx context.Context, name string, template *cf.Template
175175 param := []* cloudformation.Parameter {}
176176 for name , value := range parameters {
177177 param = append (param , & cloudformation.Parameter {
178- ParameterKey : aws .String (name ),
179- ParameterValue : aws .String (value ),
180- UsePreviousValue : aws .Bool (true ),
178+ ParameterKey : aws .String (name ),
179+ ParameterValue : aws .String (value ),
181180 })
182181 }
183182
@@ -194,6 +193,60 @@ func (s sdk) CreateStack(ctx context.Context, name string, template *cf.Template
194193 return err
195194}
196195
196+ func (s sdk ) CreateChangeSet (ctx context.Context , name string , template * cf.Template , parameters map [string ]string ) (string , error ) {
197+ logrus .Debug ("Create CloudFormation Changeset" )
198+ json , err := template .JSON ()
199+ if err != nil {
200+ return "" , err
201+ }
202+
203+ param := []* cloudformation.Parameter {}
204+ for name := range parameters {
205+ param = append (param , & cloudformation.Parameter {
206+ ParameterKey : aws .String (name ),
207+ UsePreviousValue : aws .Bool (true ),
208+ })
209+ }
210+
211+ update := fmt .Sprintf ("Update%s" , time .Now ().Format ("2006-01-02-15-04-05" ))
212+ changeset , err := s .CF .CreateChangeSetWithContext (ctx , & cloudformation.CreateChangeSetInput {
213+ ChangeSetName : aws .String (update ),
214+ ChangeSetType : aws .String (cloudformation .ChangeSetTypeUpdate ),
215+ StackName : aws .String (name ),
216+ TemplateBody : aws .String (string (json )),
217+ Parameters : param ,
218+ Capabilities : []* string {
219+ aws .String (cloudformation .CapabilityCapabilityIam ),
220+ },
221+ })
222+ if err != nil {
223+ return "" , err
224+ }
225+
226+ err = s .CF .WaitUntilChangeSetCreateCompleteWithContext (ctx , & cloudformation.DescribeChangeSetInput {
227+ ChangeSetName : changeset .Id ,
228+ })
229+ return * changeset .Id , err
230+ }
231+
232+ func (s sdk ) UpdateStack (ctx context.Context , changeset string ) error {
233+ desc , err := s .CF .DescribeChangeSetWithContext (ctx , & cloudformation.DescribeChangeSetInput {
234+ ChangeSetName : aws .String (changeset ),
235+ })
236+ if err != nil {
237+ return err
238+ }
239+
240+ if strings .HasPrefix (aws .StringValue (desc .StatusReason ), "The submitted information didn't contain changes." ) {
241+ return nil
242+ }
243+
244+ _ , err = s .CF .ExecuteChangeSet (& cloudformation.ExecuteChangeSetInput {
245+ ChangeSetName : aws .String (changeset ),
246+ })
247+ return err
248+ }
249+
197250func (s sdk ) WaitStackComplete (ctx context.Context , name string , operation int ) error {
198251 input := & cloudformation.DescribeStacksInput {
199252 StackName : aws .String (name ),
0 commit comments