Skip to content

Commit

Permalink
Merge pull request #550 from ericzbeard/fix-525
Browse files Browse the repository at this point in the history
Make including nested stacks in a change set optional
  • Loading branch information
ericzbeard authored Oct 7, 2024
2 parents 1a98cc4 + dc70ce9 commit 5583667
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
35 changes: 23 additions & 12 deletions internal/aws/cfn/cfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,29 @@ func GetStackEvents(stackName string) ([]types.StackEvent, error) {
return events, nil
}

type ChangeSetContext struct {
Template cft.Template
Params []types.Parameter
Tags map[string]string
StackName string

// ChangeSetName is optional, if "" is set, the name will be the stack name plus a timestamp
ChangeSetName string
RoleArn string

// Whether or not to include nested stacks in the change set
IncludeNested bool
}

// CreateChangeSet creates a changeset
//
// 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) {
func CreateChangeSet(ctx *ChangeSetContext) (string, error) {

template := ctx.Template
params := ctx.Params
tags := ctx.Tags
stackName := ctx.StackName
changeSetName := ctx.ChangeSetName
roleArn := ctx.RoleArn

templateBody, err := checkTemplate(template)
if err != nil {
Expand All @@ -317,7 +330,7 @@ func CreateChangeSet(
ChangeSetName: ptr.String(changeSetName),
StackName: ptr.String(stackName),
Tags: dc.MakeTags(tags),
IncludeNestedStacks: ptr.Bool(true),
IncludeNestedStacks: ptr.Bool(ctx.IncludeNested),
Parameters: params,
Capabilities: []types.Capability{
"CAPABILITY_NAMED_IAM",
Expand Down Expand Up @@ -544,8 +557,6 @@ func GetTypePermissions(name string, handlerVerb string) ([]string, error) {
*/

//config.Debugf("GetTypePermissions result: %v", result)

retval := make([]string, 0)

handlerMap, exists := result["handlers"]
Expand Down
16 changes: 13 additions & 3 deletions internal/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/aws-cloudformation/rain/internal/console"
"github.com/aws-cloudformation/rain/internal/console/spinner"
"github.com/aws-cloudformation/rain/internal/dc"
"github.com/aws-cloudformation/rain/internal/node"
"github.com/aws-cloudformation/rain/internal/s11n"
"github.com/aws-cloudformation/rain/internal/ui"
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
Expand All @@ -35,6 +34,7 @@ var ignoreUnknownParams bool
var noexec bool
var changeset bool
var experimental bool
var includeNested bool

// Cmd is the deploy command's entrypoint
var Cmd = &cobra.Command{
Expand Down Expand Up @@ -160,7 +160,17 @@ 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, changeSetName, roleArn)
ctx := cfn.ChangeSetContext{
Template: template,
Params: dc.Params,
Tags: dc.Tags,
StackName: stackName,
ChangeSetName: changeSetName,
RoleArn: roleArn,
IncludeNested: includeNested,
}
config.Debugf("ChangeSetContext: %+v", ctx)
changeSetName, createErr = cfn.CreateChangeSet(&ctx)
if createErr != nil {
if changeSetHasNoChanges(createErr.Error()) {
spinner.Pop()
Expand Down Expand Up @@ -281,7 +291,6 @@ func changeSetHasNoChanges(msg string) bool {
// hasRainMetadata returns true if the template has a resource
// with a Metadata section with a Rain node
func HasRainMetadata(template cft.Template) bool {
config.Debugf("template: %v", node.ToSJson(template.Node))
if template.Node.Content[0].Kind == yaml.DocumentNode {
template.Node = template.Node.Content[0]
}
Expand Down Expand Up @@ -320,4 +329,5 @@ func init() {
Cmd.Flags().BoolVar(&changeset, "changeset", false, "execute the changeset, rain deploy --changeset <stackName> <changeSetName>")
Cmd.Flags().StringVar(&format.NodeStyle, "node-style", "original", format.NodeStyleDocs)
Cmd.Flags().BoolVar(&experimental, "experimental", false, "Acknowledge that you want to deploy with an experimental feature")
Cmd.Flags().BoolVar(&includeNested, "nested-change-set", true, "Whether or not to include nested stacks in the change set")
}

0 comments on commit 5583667

Please sign in to comment.