Merge pull request #30431 from hashicorp/replace-flag-clarifications

Make -replace flag clearer
This commit is contained in:
Laura Pacilio 2022-02-01 10:47:04 -05:00 committed by GitHub
commit d3bc3a63dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 62 deletions

View File

@ -39,10 +39,8 @@ Terraform will propose the plan to you and prompt you to approve it before
taking the described actions, unless you waive that prompt by using the
`-auto-approve` option.
When performing its own plan, `terraform apply` supports all of the same
[planning modes](/cli/commands/plan#planning-modes) and
[planning options](/cli/commands/plan#planning-options) that `terraform plan` would
accept, so you can customize how Terraform will create the plan.
-> **Tip:** When you run `terraform apply` without a saved plan file, you can use all of the [planning modes](/cli/commands/plan#planning-modes) and
[planning options](/cli/commands/plan#planning-options) available for `terraform plan`. This lets you customize how Terraform will create the plan.
### Saved Plan Mode
@ -67,10 +65,7 @@ plan`'s planning modes and planning options. For details, see:
### Apply Options
The following options allow you to change various details about how the
apply command executes and reports on the apply operation. If you are running
`terraform apply` _without_ a previously-saved plan file, these options are
_in addition to_ the planning modes and planning options described for
[`terraform plan`](/cli/commands/plan).
apply command executes and reports on the apply operation.
* `-auto-approve` - Skips interactive approval of plan before applying. This
option is ignored when you pass a previously-saved plan file, because
@ -114,6 +109,10 @@ _in addition to_ the planning modes and planning options described for
[walks the graph](/internals/graph#walking-the-graph). Defaults to
10\.
- All [planning modes](/cli/commands/plan#planning-modes) and
[planning options](/cli/commands/plan#planning-options) for
`terraform plan` - Customize how Terraform will create the plan. Only available when you run `terraform apply` without a saved plan file.
For configurations using
[the `local` backend](/language/settings/backends/local) only,
`terraform apply` also accepts the legacy options

View File

@ -82,12 +82,9 @@ The remaining sections on this page describe the various options:
## Planning Modes
The section above described Terraform's default planning behavior, which is
intended for changing the remote system to match with changes you've made to
your configuration.
Terraform has two alternative planning modes, each of which creates a plan with
a different intended outcome:
The previous section describes Terraform's default planning behavior, which
changes the remote system to match the changes you make to
your configuration. Terraform has two alternative planning modes, each of which creates a plan with a different intended outcome. These options are available for both `terraform plan` and [`terraform apply`](/cli/commands/apply).
* **Destroy mode:** creates a plan whose goal is to destroy all remote objects
that currently exist, leaving an empty Terraform state. This can be useful
@ -127,70 +124,35 @@ and later.
## Planning Options
In addition to the planning _modes_ described above, there are also several
additional options that can modify details of the behavior of the planning
step.
In addition to alternate [planning modes](#planning-modes), there are several options that can modify planning behavior. These options are available for both `terraform plan` and [`terraform apply`](/cli/commands/apply).
When you use `terraform apply` without passing it a saved plan file, it
incorporates the `terraform plan` command functionality and so the planning
options in this section, along with the planning mode selection options in
the previous section, are also available with the same meanings on
`terraform apply`.
- `-refresh=false` - Disables the default behavior of synchronizing the
Terraform state with remote objects before checking for configuration changes. This can make the planning operation faster by reducing the number of remote API requests. However, setting `refresh=false` causes Terraform to ignore external changes, which could result in an incomplete or incorrect plan. You cannot use `refresh=false` in refresh-only planning mode because it would effectively disable the entirety of the planning operation.
* `-refresh=false` - Disables the default behavior of synchronizing the
Terraform state with remote objects before checking for configuration changes.
- `-replace=ADDRESS` - Instructs Terraform to plan to replace the
resource instance with the given address. This is helpful when one or more remote objects have become degraded, and you can use replacement objects with the same configuratation to align with immutable infrastructure patterns. Terraform will use a "replace" action if the specified resource would normally cause an "update" action or no action at all. Include this option multiple times to replace several objects at once. You cannot use `-replace` with the `-destroy` option, and it is only available from Terraform v0.15.2 onwards. For earlier versions, use [`terraform taint`](/cli/commands/taint) to achieve a similar result.
This option can potentially make the planning operation faster by reducing
the number of remote API requests, but it comes at the expense of having
Terraform not take into account any changes that might've happened outside
of Terraform, and thus the resulting plan may not be complete or correct.
This option is not available in the "refresh only" planning mode, because
it would effectively disable the entirety of the planning operation in that
case.
* `-replace=ADDRESS` - Instructs Terraform to plan to replace the single
resource instance with the given address. If the given instance would
normally have caused only an "update" action, or no action at all, then
Terraform will choose a "replace" action instead.
You can use this option if you have learned that a particular remote object
has become degraded in some way. If you are using immutable infrastructure
patterns then you may wish to respond to that by replacing the
malfunctioning object with a new object that has the same configuration.
This option is allowed only in the normal planning mode, so this option
is incompatible with the `-destroy` option.
The `-replace=...` option is available only from Terraform v0.15.2 onwards.
For earlier versions, you can achieve a similar effect (with some caveats)
using [`terraform taint`](/cli/commands/taint).
* `-target=ADDRESS` - Instructs Terraform to focus its planning efforts only
- `-target=ADDRESS` - Instructs Terraform to focus its planning efforts only
on resource instances which match the given address and on any objects that
those instances depend on.
This command is for exceptional use only. See
[Resource Targeting](#resource-targeting)
below for more information.
-> **Note:** Use `-target=ADDRESS` in exceptional circumstances only, such as recovering from mistakes or working around Terraform limitations. Refer to [Resource Targeting](#resource-targeting) for more details.
* `-var 'NAME=VALUE'` - Sets a value for a single
- `-var 'NAME=VALUE'` - Sets a value for a single
[input variable](/language/values/variables) declared in the
root module of the configuration. Use this option multiple times to set
more than one variable. For more information see
[Input Variables on the Command Line](#input-variables-on-the-command-line),
below.
more than one variable. Refer to
[Input Variables on the Command Line](#input-variables-on-the-command-line) for more information.
* `-var-file=FILENAME` - Sets values for potentially many
- `-var-file=FILENAME` - Sets values for potentially many
[input variables](/language/values/variables) declared in the
root module of the configuration, using definitions from a
["tfvars" file](/language/values/variables#variable-definitions-tfvars-files).
Use this option multiple times to include values from more than one file.
There are several other ways to set values for input variables in the root
module, aside from the `-var` and `-var-file` options. For more information,
see
[Assigning Values to Root Module Variables](/language/values/variables#assigning-values-to-root-module-variables).
module, aside from the `-var` and `-var-file` options. Refer to
[Assigning Values to Root Module Variables](/language/values/variables#assigning-values-to-root-module-variables) for more information.
### Input Variables on the Command Line