mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-29 15:01:44 -04:00
This document now lives at: - https://learn.hashicorp.com/terraform/development/running-terraform-in-automation ...and terraform.io has been redirecting to there for quite a while. This commit removes the extra copy so that the text of the two versions doesn't drift, and updates existing links to point to the new location.
76 lines
3.2 KiB
Markdown
76 lines
3.2 KiB
Markdown
---
|
|
layout: "docs"
|
|
page_title: "Command: apply"
|
|
sidebar_current: "docs-commands-apply"
|
|
description: |-
|
|
The `terraform apply` command is used to apply the changes required to reach the desired state of the configuration, or the pre-determined set of actions generated by a `terraform plan` execution plan.
|
|
---
|
|
|
|
# Command: apply
|
|
|
|
The `terraform apply` command is used to apply the changes required
|
|
to reach the desired state of the configuration, or the pre-determined
|
|
set of actions generated by a `terraform plan` execution plan.
|
|
|
|
## Usage
|
|
|
|
Usage: `terraform apply [options] [dir-or-plan]`
|
|
|
|
By default, `apply` scans the current directory for the configuration
|
|
and applies the changes appropriately. However, a path to another configuration
|
|
or an execution plan can be provided. Explicit execution plans files can be
|
|
used to split plan and apply into separate steps within
|
|
[automation systems](https://learn.hashicorp.com/terraform/development/running-terraform-in-automation).
|
|
|
|
The command-line flags are all optional. The list of available flags are:
|
|
|
|
* `-backup=path` - Path to the backup file. Defaults to `-state-out` with
|
|
the ".backup" extension. Disabled by setting to "-".
|
|
|
|
* `-compact-warnings` - If Terraform produces any warnings that are not
|
|
accompanied by errors, show them in a more compact form that includes only
|
|
the summary messages.
|
|
|
|
* `-lock=true` - Lock the state file when locking is supported.
|
|
|
|
* `-lock-timeout=0s` - Duration to retry a state lock.
|
|
|
|
* `-input=true` - Ask for input for variables if not directly set.
|
|
|
|
* `-auto-approve` - Skip interactive approval of plan before applying.
|
|
|
|
* `-no-color` - Disables output with coloring.
|
|
|
|
* `-parallelism=n` - Limit the number of concurrent operation as Terraform
|
|
[walks the graph](/docs/internals/graph.html#walking-the-graph). Defaults to
|
|
10.
|
|
|
|
* `-refresh=true` - Update the state for each resource prior to planning
|
|
and applying. This has no effect if a plan file is given directly to
|
|
apply.
|
|
|
|
* `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
|
|
Ignored when [remote state](/docs/state/remote.html) is used.
|
|
|
|
* `-state-out=path` - Path to write updated state file. By default, the
|
|
`-state` path will be used. Ignored when
|
|
[remote state](/docs/state/remote.html) is used.
|
|
|
|
* `-target=resource` - A [Resource
|
|
Address](/docs/internals/resource-addressing.html) to target. For more
|
|
information, see
|
|
[the targeting docs from `terraform plan`](/docs/commands/plan.html#resource-targeting).
|
|
|
|
* `-var 'foo=bar'` - Set a variable in the Terraform configuration. This flag
|
|
can be set multiple times. Variable values are interpreted as
|
|
[HCL](/docs/configuration/syntax.html#HCL), so list and map values can be
|
|
specified via this flag.
|
|
|
|
* `-var-file=foo` - Set variables in the Terraform configuration from
|
|
a [variable file](/docs/configuration/variables.html#variable-files). If
|
|
a `terraform.tfvars` or any `.auto.tfvars` files are present in the current
|
|
directory, they will be automatically loaded. `terraform.tfvars` is loaded
|
|
first and the `.auto.tfvars` files after in alphabetical order. Any files
|
|
specified by `-var-file` override any values set automatically from files in
|
|
the working directory. This flag can be used multiple times.
|