rm

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Usage:
  rm <stack>

Aliases:
  rm, remove, del, delete

Flags:
  -d, --detach   Once removal has started, don't wait around for it to finish.
  -h, --help     help for rm
  -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>",
	Short:                 "Delete a running CloudFormation stack",
	Long:                  "Deletes the CloudFormation stack named <stack> and waits for the action to complete.",
	Args:                  cobra.ExactArgs(1),
	Annotations:           cmd.StackAnnotation,
	Aliases:               []string{"remove", "del", "delete"},
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		stackName := args[0]

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

		if *stack.EnableTerminationProtection {
			spinner.Pause()

			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))
			}

			spinner.Resume()
		}

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

			spinner.Pause()
			fmt.Println(output)

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

		spinner.Pop()

		err = cfn.DeleteStack(stackName)
		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 := ui.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

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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