From 9b6c577eb2f7ad7faa2a063d2b7924d98e70218a Mon Sep 17 00:00:00 2001 From: Tatsuya Mori Date: Fri, 1 Apr 2022 23:10:39 +0900 Subject: [PATCH 1/3] Exit with a success code instead of a panic when change set includes no change. --- internal/aws/cfn/cfn.go | 10 +++++++++- internal/cmd/deploy/deploy.go | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/aws/cfn/cfn.go b/internal/aws/cfn/cfn.go index c786e845..9a00cd46 100644 --- a/internal/aws/cfn/cfn.go +++ b/internal/aws/cfn/cfn.go @@ -21,6 +21,10 @@ import ( "github.com/aws/smithy-go/ptr" ) +const noChangeFoundMsg = "The submitted information didn't contain changes. Submit different information to create a change set." + +var ErrNoChange = errors.New(noChangeFoundMsg) + var liveStatuses = []types.StackStatus{ "CREATE_IN_PROGRESS", "CREATE_FAILED", @@ -261,7 +265,11 @@ func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[s config.Debugf("ChangeSet status: %s", status) if status == "FAILED" { - return changeSetName, errors.New(ptr.ToString(res.StatusReason)) + if ptr.ToString(res.StatusReason) == noChangeFoundMsg { + return changeSetName, ErrNoChange + } else { + return changeSetName, errors.New(ptr.ToString(res.StatusReason)) + } } if strings.HasSuffix(status, "_COMPLETE") { diff --git a/internal/cmd/deploy/deploy.go b/internal/cmd/deploy/deploy.go index d017e3b8..a35ea3e4 100644 --- a/internal/cmd/deploy/deploy.go +++ b/internal/cmd/deploy/deploy.go @@ -159,7 +159,13 @@ YAML: spinner.Push("Creating change set") changeSetName, createErr := cfn.CreateChangeSet(template, parameters, combinedTags, stackName, roleArn) if createErr != nil { - panic(ui.Errorf(createErr, "error creating changeset")) + switch createErr { + case cfn.ErrNoChange: + fmt.Println(console.Green("\nChange set was created, but there is no change. Deploy was skipped.")) + return + default: + panic(ui.Errorf(createErr, "error creating changeset")) + } } changeSetStatus, err := cfn.GetChangeSet(stackName, changeSetName) From 8b2cb53ab18d4102a29b0c1f82614ef79f82f754 Mon Sep 17 00:00:00 2001 From: Tatsuya Mori Date: Sat, 2 Apr 2022 00:05:50 +0900 Subject: [PATCH 2/3] Moving the logic which determines whether change set includes changes or not into deploy.go. --- internal/aws/cfn/cfn.go | 10 +--------- internal/cmd/deploy/deploy.go | 13 +++++++------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/internal/aws/cfn/cfn.go b/internal/aws/cfn/cfn.go index 9a00cd46..c786e845 100644 --- a/internal/aws/cfn/cfn.go +++ b/internal/aws/cfn/cfn.go @@ -21,10 +21,6 @@ import ( "github.com/aws/smithy-go/ptr" ) -const noChangeFoundMsg = "The submitted information didn't contain changes. Submit different information to create a change set." - -var ErrNoChange = errors.New(noChangeFoundMsg) - var liveStatuses = []types.StackStatus{ "CREATE_IN_PROGRESS", "CREATE_FAILED", @@ -265,11 +261,7 @@ func CreateChangeSet(template cft.Template, params []types.Parameter, tags map[s config.Debugf("ChangeSet status: %s", status) if status == "FAILED" { - if ptr.ToString(res.StatusReason) == noChangeFoundMsg { - return changeSetName, ErrNoChange - } else { - return changeSetName, errors.New(ptr.ToString(res.StatusReason)) - } + return changeSetName, errors.New(ptr.ToString(res.StatusReason)) } if strings.HasSuffix(status, "_COMPLETE") { diff --git a/internal/cmd/deploy/deploy.go b/internal/cmd/deploy/deploy.go index a35ea3e4..9b311a23 100644 --- a/internal/cmd/deploy/deploy.go +++ b/internal/cmd/deploy/deploy.go @@ -19,6 +19,8 @@ import ( "github.com/spf13/cobra" ) +const noChangeFoundMsg = "The submitted information didn't contain changes. Submit different information to create a change set." + type configFileFormat struct { Parameters map[string]string `yaml:"Parameters"` Tags map[string]string `yaml:"Tags"` @@ -159,12 +161,11 @@ YAML: spinner.Push("Creating change set") changeSetName, createErr := cfn.CreateChangeSet(template, parameters, combinedTags, stackName, roleArn) if createErr != nil { - switch createErr { - case cfn.ErrNoChange: - fmt.Println(console.Green("\nChange set was created, but there is no change. Deploy was skipped.")) - return - default: - panic(ui.Errorf(createErr, "error creating changeset")) + if createErr.Error() == noChangeFoundMsg { + fmt.Println(console.Green("\nChange set was created, but there is no change. Deploy was skipped.")) + return + } else { + panic(ui.Errorf(createErr, "error creating changeset")) } } From fef8065ffa043e4b9ccdde771d9712c5357c8018 Mon Sep 17 00:00:00 2001 From: Tatsuya Mori Date: Sat, 2 Apr 2022 01:12:50 +0900 Subject: [PATCH 3/3] Use spinner.Pop() --- internal/cmd/deploy/deploy.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/cmd/deploy/deploy.go b/internal/cmd/deploy/deploy.go index 9b311a23..6cd177a2 100644 --- a/internal/cmd/deploy/deploy.go +++ b/internal/cmd/deploy/deploy.go @@ -162,7 +162,8 @@ YAML: changeSetName, createErr := cfn.CreateChangeSet(template, parameters, combinedTags, stackName, roleArn) if createErr != nil { if createErr.Error() == noChangeFoundMsg { - fmt.Println(console.Green("\nChange set was created, but there is no change. Deploy was skipped.")) + spinner.Pop() + fmt.Println(console.Green("Change set was created, but there is no change. Deploy was skipped.")) return } else { panic(ui.Errorf(createErr, "error creating changeset"))