Skip to content

Commit

Permalink
Merge pull request #154 from Appliscale/delete-change-set
Browse files Browse the repository at this point in the history
Delete Change Set #153
  • Loading branch information
maxiwoj authored Aug 31, 2018
2 parents 2f33593 + 9f21717 commit fc195e8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
5 changes: 5 additions & 0 deletions awsapi/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type CloudFormationAPI interface {
CreateChangeSet(input *cloudformation.CreateChangeSetInput) (*cloudformation.CreateChangeSetOutput, error)
DescribeChangeSet(input *cloudformation.DescribeChangeSetInput) (*cloudformation.DescribeChangeSetOutput, error)
WaitUntilChangeSetCreateComplete(input *cloudformation.DescribeChangeSetInput) error
DeleteChangeSet(input *cloudformation.DeleteChangeSetInput) (*cloudformation.DeleteChangeSetOutput, error)
}

type AWSCloudFormationAPI struct {
Expand Down Expand Up @@ -63,3 +64,7 @@ func (cf *AWSCloudFormationAPI) DescribeChangeSet(input *cloudformation.Describe
func (cf *AWSCloudFormationAPI) WaitUntilChangeSetCreateComplete(input *cloudformation.DescribeChangeSetInput) error {
return cf.api.WaitUntilChangeSetCreateComplete(input)
}

func (cf *AWSCloudFormationAPI) DeleteChangeSet(input *cloudformation.DeleteChangeSetInput) (*cloudformation.DeleteChangeSetOutput, error) {
return cf.api.DeleteChangeSet(input)
}
10 changes: 10 additions & 0 deletions cliparser/cliparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var DestroySinkMode = "destroy-remote-sink"
var CreateParametersMode = "create-parameters"
var SetStackPolicyMode = "set-stack-policy"
var CreateChangeSetMode = "create-change-set"
var DeleteChangeSetMode = "delete-change-set"
var LintMode = "lint"

var ChangeSetDefaultName string
Expand Down Expand Up @@ -126,6 +127,10 @@ func ParseCliArguments(args []string) (cliArguments CliArguments, err error) {
createChangeSetLintConfiguration = createChangeSet.Flag("lint-configuration", "A path to the configuration file").String()
createChangeSetEstimateCost = createChangeSet.Flag("estimate-cost", "Enable cost estimation during validation").Bool()

deleteChangeSet = app.Command(DeleteChangeSetMode, "Deletes a changeSet on aws")
deleteChangeSetStackName = deleteChangeSet.Arg("stack", "An AWS stack Name").Required().String()
deleteChangeSetName = deleteChangeSet.Arg("change-set", "An AWS Change Set name").Required().String()

deleteStack = app.Command(DestroyStackMode, "Deletes a stack on aws")
deleteStackName = deleteStack.Arg("stack", "An AWS stack name.").Required().String()

Expand Down Expand Up @@ -251,6 +256,11 @@ func ParseCliArguments(args []string) (cliArguments CliArguments, err error) {
cliArguments.LinterConfiguration = createChangeSetLintConfiguration
cliArguments.EstimateCost = createChangeSetEstimateCost

case deleteChangeSet.FullCommand():
cliArguments.Mode = &DeleteChangeSetMode
cliArguments.Stack = deleteChangeSetStackName
cliArguments.ChangeSet = deleteChangeSetName

// set up remote sink
case setupSink.FullCommand():
cliArguments.Mode = &SetupSinkMode
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func main() {
}
}

if *ctx.CliArguments.Mode == cliparser.DeleteChangeSetMode {
ctx.InitializeAwsAPI()
utilities.CheckErrorCodeAndExit(stack.DeleteChangeSet(&ctx))
}

if *ctx.CliArguments.Mode == cliparser.UpdateStackMode {
ctx.InitializeAwsAPI()
if *ctx.CliArguments.SkipValidation || validator.ValidateAndEstimateCost(&ctx) {
Expand Down
27 changes: 22 additions & 5 deletions stack/changeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ func createChangeSetInput(template *string, stackName *string, params []*cloudfo
return templateStruct, nil
}

func createDeleteChangeSetInput(ctx *context.Context) cloudformation.DeleteChangeSetInput {
return cloudformation.DeleteChangeSetInput{
ChangeSetName: ctx.CliArguments.ChangeSet,
StackName: ctx.CliArguments.Stack,
}
}
func DeleteChangeSet(ctx *context.Context) (err error) {
templateStruct := createDeleteChangeSetInput(ctx)
_, err = ctx.CloudFormation.DeleteChangeSet(&templateStruct)
if err != nil {
ctx.Logger.Error(err.Error())
return
}
ctx.Logger.Info("Deletion of Change Set " + *ctx.CliArguments.ChangeSet + " request successful")
return
}

func NewChangeSet(context *context.Context) (err error) {
template, stackName, err := getTemplateFromFile(context)
if err != nil {
Expand Down Expand Up @@ -72,23 +89,23 @@ func shouldExecuteChangeSet() bool {
return false
}

func describeChangeSet(context *context.Context) (err error) {
func describeChangeSet(context *context.Context) error {
context.Logger.Info("Waiting for change set creation...")
describeChangeSetInput := cloudformation.DescribeChangeSetInput{
ChangeSetName: context.CliArguments.ChangeSet,
StackName: context.CliArguments.Stack,
}

err = context.CloudFormation.WaitUntilChangeSetCreateComplete(&describeChangeSetInput)
err := context.CloudFormation.WaitUntilChangeSetCreateComplete(&describeChangeSetInput)
if err != nil {
context.Logger.Error(err.Error())
return
return err
}

describeChangeSetOutput, err := context.CloudFormation.DescribeChangeSet(&describeChangeSetInput)
if err != nil {
context.Logger.Error(err.Error())
return
return err
}

_, table := initStackTableWriter()
Expand All @@ -111,7 +128,7 @@ func describeChangeSet(context *context.Context) (err error) {
})
}
table.Render()
return
return nil
}

func initStackTableWriter() (*progress.ParseWriter, *tablewriter.Table) {
Expand Down
13 changes: 13 additions & 0 deletions stack/mocks/mock_aws_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fc195e8

Please sign in to comment.