Skip to content

Commit

Permalink
Merge pull request #452 from ericzbeard/fix-448
Browse files Browse the repository at this point in the history
Add option to name a change set on creation
  • Loading branch information
ericzbeard authored Jul 11, 2024
2 parents b512a2f + 09c7d6c commit edd427b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 13 additions & 2 deletions internal/aws/cfn/cfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,16 @@ func GetStackEvents(stackName string) ([]types.StackEvent, error) {
}

// CreateChangeSet creates a changeset
func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[string]string, stackName string, roleArn string) (string, error) {
//
// changeSetName is optional, if "" is passed in, the name will be the stack name plus a timestamp
func CreateChangeSet(
template cft.Template,
params []types.Parameter,
tags map[string]string,
stackName string,
changeSetName string,
roleArn string) (string, error) {

templateBody, err := checkTemplate(template)
if err != nil {
return "", err
Expand All @@ -289,7 +298,9 @@ func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[s
changeSetType = "UPDATE"
}

changeSetName := stackName + "-" + fmt.Sprint(time.Now().Unix())
if changeSetName == "" {
changeSetName = stackName + "-" + fmt.Sprint(time.Now().Unix())
}

input := &cloudformation.CreateChangeSetInput{
ChangeSetType: types.ChangeSetType(changeSetType),
Expand Down
13 changes: 9 additions & 4 deletions internal/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ YAML:
TagKey: TagValue
...
To create a changeset:
To create a changeset (with optional stackName and changeSetName):
rain deploy --no-exec <template> [stackName]
rain deploy --no-exec <template> [stackName] [changeSetName]
To execute a changeset:
rain deploy --changeset <stackName> <changeSetName>
To list and delete changesets, use the ls and rm commands.
`,
Args: cobra.RangeArgs(1, 2),
Args: cobra.RangeArgs(1, 3),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {

Expand Down Expand Up @@ -107,6 +107,11 @@ To list and delete changesets, use the ls and rm commands.
suppliedStackName = ""
}

// Optionally name the change set
if len(args) == 3 {
changeSetName = args[2]
}

// Package template
if experimental {
cftpkg.Experimental = true
Expand Down Expand Up @@ -135,7 +140,7 @@ To list and delete changesets, use the ls and rm commands.
// Create change set
spinner.Push("Creating change set")
var createErr error
changeSetName, createErr = cfn.CreateChangeSet(template, dc.Params, dc.Tags, stackName, roleArn)
changeSetName, createErr = cfn.CreateChangeSet(template, dc.Params, dc.Tags, stackName, changeSetName, roleArn)
if createErr != nil {
if changeSetHasNoChanges(createErr.Error()) {
spinner.Pop()
Expand Down

0 comments on commit edd427b

Please sign in to comment.