mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
command: enable destroy
This commit is contained in:
parent
f302e7d1bb
commit
245c1ce05a
@ -115,6 +115,23 @@ func (c *ApplyCommand) Run(args []string) int {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
if c.Input() {
|
if c.Input() {
|
||||||
|
if c.Destroy {
|
||||||
|
v, err := c.UIInput().Input(&terraform.InputOpts{
|
||||||
|
Id: "destroy",
|
||||||
|
Query: "Do you really want to destroy?",
|
||||||
|
Description: "Terraform will delete all your manage infrastructure.\n" +
|
||||||
|
"There is no undo. Only 'yes' will be accepted to confirm.",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
c.Ui.Error(fmt.Sprintf("Error asking for confirmation: %s", err))
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if v != "yes" {
|
||||||
|
c.Ui.Output("Destroy cancelled.")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := ctx.Input(); err != nil {
|
if err := ctx.Input(); err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf("Error configuring: %s", err))
|
c.Ui.Error(fmt.Sprintf("Error configuring: %s", err))
|
||||||
return 1
|
return 1
|
||||||
@ -271,6 +288,22 @@ func (c *ApplyCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApplyCommand) Help() string {
|
func (c *ApplyCommand) Help() string {
|
||||||
|
if c.Destroy {
|
||||||
|
return c.helpDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.helpApply()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ApplyCommand) Synopsis() string {
|
||||||
|
if c.Destroy {
|
||||||
|
return "Destroy Terraform-managed infrastructure"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Builds or changes infrastructure"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ApplyCommand) helpApply() string {
|
||||||
helpText := `
|
helpText := `
|
||||||
Usage: terraform apply [options] [DIR]
|
Usage: terraform apply [options] [DIR]
|
||||||
|
|
||||||
@ -315,6 +348,40 @@ Options:
|
|||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApplyCommand) Synopsis() string {
|
func (c *ApplyCommand) helpDestroy() string {
|
||||||
return "Builds or changes infrastructure"
|
helpText := `
|
||||||
|
Usage: terraform destroy [options] [DIR]
|
||||||
|
|
||||||
|
Destroy Terraform-managed infrastructure.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
-backup=path Path to backup the existing state file before
|
||||||
|
modifying. Defaults to the "-state-out" path with
|
||||||
|
".backup" extension. Set to "-" to disable backup.
|
||||||
|
|
||||||
|
-input=true Ask for input for destroy confirmation.
|
||||||
|
|
||||||
|
-no-color If specified, output won't contain any color.
|
||||||
|
|
||||||
|
-refresh=true Update state prior to checking for differences. This
|
||||||
|
has no effect if a plan file is given to apply.
|
||||||
|
|
||||||
|
-state=path Path to read and save state (unless state-out
|
||||||
|
is specified). Defaults to "terraform.tfstate".
|
||||||
|
|
||||||
|
-state-out=path Path to write state to that is different than
|
||||||
|
"-state". This can be used to preserve the old
|
||||||
|
state.
|
||||||
|
|
||||||
|
-var 'foo=bar' Set a variable in the Terraform configuration. This
|
||||||
|
flag can be set multiple times.
|
||||||
|
|
||||||
|
-var-file=foo Set variables in the Terraform configuration from
|
||||||
|
a file. If "terraform.tfvars" is present, it will be
|
||||||
|
automatically loaded if this flag is not specified.
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
return strings.TrimSpace(helpText)
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,13 @@ func (m *Meta) Input() bool {
|
|||||||
return !test && m.input && len(m.variables) == 0
|
return !test && m.input && len(m.variables) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UIInput returns a UIInput object to be used for asking for input.
|
||||||
|
func (m *Meta) UIInput() terraform.UIInput {
|
||||||
|
return &UIInput{
|
||||||
|
Colorize: m.Colorize(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// contextOpts returns the options to use to initialize a Terraform
|
// contextOpts returns the options to use to initialize a Terraform
|
||||||
// context with the settings from this Meta.
|
// context with the settings from this Meta.
|
||||||
func (m *Meta) contextOpts() *terraform.ContextOpts {
|
func (m *Meta) contextOpts() *terraform.ContextOpts {
|
||||||
@ -133,9 +140,7 @@ func (m *Meta) contextOpts() *terraform.ContextOpts {
|
|||||||
vs[k] = v
|
vs[k] = v
|
||||||
}
|
}
|
||||||
opts.Variables = vs
|
opts.Variables = vs
|
||||||
opts.UIInput = &UIInput{
|
opts.UIInput = m.UIInput()
|
||||||
Colorize: m.Colorize(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return &opts
|
return &opts
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user