rm

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Example (Rm_help)
package main

import (
	"os"

	"github.com/aws-cloudformation/rain/internal/cmd/rm"
)

func main() {
	os.Args = []string{
		os.Args[0],
		"--help",
	}

	rm.Cmd.Execute()
}
Output:

Deletes the CloudFormation stack named <stack> and waits for the action to complete. With -c, deletes a changeset named [changeset].

Usage:
  rm <stack> [changeset]

Aliases:
  rm, remove, del, delete

Flags:
  -c, --changeset         delete a changeset
  -d, --detach            once removal has started, don't wait around for it to finish
  -h, --help              help for rm
      --role-arn string   ARN of an IAM role that CloudFormation should assume to remove the stack
  -y, --yes               don't ask questions; just delete

Index

Examples

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:                   "rm <stack> [changeset]",
	Short:                 "Delete a CloudFormation stack or changeset",
	Long:                  "Deletes the CloudFormation stack named <stack> and waits for the action to complete. With -c, deletes a changeset named [changeset].",
	Args:                  cobra.MaximumNArgs(2),
	Aliases:               []string{"remove", "del", "delete"},
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			panic("at least one argument is required")
		}
		stackName := args[0]

		spinner.Push("Fetching stack status")
		stack, err := cfn.GetStack(stackName)
		if err != nil {
			panic(ui.Errorf(err, "unable to get stack '%s'", stackName))
		}
		spinner.Pop()

		if changeset {
			if len(args) != 2 {
				panic("expected 2 arguments: stackName changeSetName")
			}
			if err := DeleteChangeSet(&stack, args[1]); err != nil {
				panic(err)
			}
			return
		}

		if !yes {
			output, _ := cfn.GetStackOutput(stack)

			fmt.Println(output)

			if !console.Confirm(false, "Are you sure you want to delete this stack?") {
				panic(fmt.Errorf("user cancelled deletion of stack '%s'", stackName))
			}
		}

		if *stack.EnableTerminationProtection {

			if yes || console.Confirm(false, "This stack has termination protection enabled. Do you wish to disable it?") {
				spinner.Push("Disabling termination protection")
				if err := cfn.SetTerminationProtection(stackName, false); err != nil {
					panic(ui.Errorf(err, "unable to set termination protection of stack '%s'", stackName))
				}
				spinner.Pop()
			} else {
				panic(fmt.Errorf("user cancelled deletion of stack '%s'", stackName))
			}
		}

		err = cfn.DeleteStack(stackName, roleArn)
		if err != nil {
			panic(ui.Errorf(err, "unable to delete stack '%s'", stackName))
		}

		if detach {
			fmt.Printf("Detaching. You can check your stack's status with: rain watch %s\n", stackName)
		} else {
			status, messages := cfn.WaitForStackToSettle(stackName)
			stack, _ = cfn.GetStack(stackName)

			if status == "DELETE_COMPLETE" {
				fmt.Println(console.Green(fmt.Sprintf("Successfully deleted stack '%s'", stackName)))
				return
			}

			fmt.Fprintln(os.Stderr, console.Red(fmt.Sprintf("Failed to delete stack '%s'", stackName)))

			if len(messages) > 0 {
				fmt.Fprintln(os.Stderr, console.Yellow("Messages:"))
				for _, message := range messages {
					fmt.Fprintf(os.Stderr, "  - %s\n", message)
				}
			}

			os.Exit(1)
		}
	},
}

Cmd is the rm command's entrypoint

Functions

func DeleteChangeSet added in v1.8.0

func DeleteChangeSet(stack *types.Stack, changeSetName string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL