github.com/cycloidio/terraform@v1.1.10-0.20220513142504-76d5c768dc63/website/docs/cli/commands/apply.mdx (about)

     1  ---
     2  page_title: 'Command: apply'
     3  description: >-
     4    The terraform apply command executes the actions proposed in a Terraform plan
     5    to create, update, or destroy infrastructure.
     6  ---
     7  
     8  # Command: apply
     9  
    10  > **Hands-on:** Try the [Terraform: Get Started](https://learn.hashicorp.com/collections/terraform/aws-get-started?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) collection on HashiCorp Learn.
    11  
    12  The `terraform apply` command executes the actions proposed in a Terraform
    13  plan.
    14  
    15  The most straightforward way to use `terraform apply` is to run it without
    16  any arguments at all, in which case it will automatically create a new
    17  execution plan (as if you had run `terraform plan`) and then prompt you to
    18  approve that plan, before taking the indicated actions.
    19  
    20  Another way to use `terraform apply` is to pass it the filename of a saved
    21  plan file you created earlier with `terraform plan -out=...`, in which case
    22  Terraform will apply the changes in the plan without any confirmation prompt.
    23  This two-step workflow is primarily intended for when
    24  [running Terraform in automation](https://learn.hashicorp.com/tutorials/terraform/automate-terraform?in=terraform/automation&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS).
    25  
    26  ## Usage
    27  
    28  Usage: `terraform apply [options] [plan file]`
    29  
    30  The behavior of `terraform apply` differs significantly depending on whether
    31  you pass it the filename of a previously-saved plan file.
    32  
    33  ### Automatic Plan Mode
    34  
    35  In the default case, with no saved plan file, `terraform apply` creates its own
    36  plan of action, in the same way that [`terraform plan`](/cli/commands/plan) would.
    37  
    38  Terraform will propose the plan to you and prompt you to approve it before
    39  taking the described actions, unless you waive that prompt by using the
    40  `-auto-approve` option.
    41  
    42  -> **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
    43  [planning options](/cli/commands/plan#planning-options) available for `terraform plan`. This lets you customize how Terraform will create the plan.
    44  
    45  ### Saved Plan Mode
    46  
    47  If you pass the filename of a previously-saved plan file, `terraform apply`
    48  performs exactly the steps specified by that plan file. It does not prompt for
    49  approval; if you want to inspect a plan file before applying it, you can use
    50  [`terraform show`](/cli/commands/show).
    51  
    52  When using a saved plan, none of the planning modes or planning options linked
    53  above are supported; these options only affect Terraform's decisions about which
    54  actions to take, and the plan file contains the final results of those
    55  decisions.
    56  
    57  ### Plan Options
    58  
    59  When run without a saved plan file, `terraform apply` supports all of `terraform
    60  plan`'s planning modes and planning options. For details, see:
    61  
    62  * [Planning Modes](/cli/commands/plan#planning-modes)
    63  * [Planning Options](/cli/commands/plan#planning-options)
    64  
    65  ### Apply Options
    66  
    67  The following options allow you to change various details about how the
    68  apply command executes and reports on the apply operation.
    69  
    70  * `-auto-approve` - Skips interactive approval of plan before applying. This
    71    option is ignored when you pass a previously-saved plan file, because
    72    Terraform considers you passing the plan file as the approval and so
    73    will never prompt in that case.
    74  
    75  * `-compact-warnings` - Shows any warning messages in a compact form which
    76    includes only the summary messages, unless the warnings are accompanied by
    77    at least one error and thus the warning text might be useful context for
    78    the errors.
    79  
    80  * `-input=false` - Disables all of Terraform's interactive prompts. Note that
    81    this also prevents Terraform from prompting for interactive approval of a
    82    plan, so Terraform will conservatively assume that you do not wish to
    83    apply the plan, causing the operation to fail. If you wish to run Terraform
    84    in a non-interactive context, see
    85    [Running Terraform in Automation](https://learn.hashicorp.com/tutorials/terraform/automate-terraform?in=terraform/automation&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) for some
    86    different approaches.
    87  
    88  * `-json` - Enables the [machine readable JSON UI][machine-readable-ui] output.
    89    This implies `-input=false`, so the configuration must have no unassigned
    90    variable values to continue. To enable this flag, you must also either enable
    91    the `-auto-approve` flag or specify a previously-saved plan.
    92  
    93    [machine-readable-ui]: /internals/machine-readable-ui
    94  
    95  * `-lock=false` - Don't hold a state lock during the operation. This is
    96    dangerous if others might concurrently run commands against the same
    97    workspace.
    98  
    99  * `-lock-timeout=DURATION` - Unless locking is disabled with `-lock=false`,
   100    instructs Terraform to retry acquiring a lock for a period of time before
   101    returning an error. The duration syntax is a number followed by a time
   102    unit letter, such as "3s" for three seconds.
   103  
   104  * `-no-color` - Disables terminal formatting sequences in the output. Use this
   105    if you are running Terraform in a context where its output will be
   106    rendered by a system that cannot interpret terminal formatting.
   107  
   108  * `-parallelism=n` - Limit the number of concurrent operation as Terraform
   109    [walks the graph](/internals/graph#walking-the-graph). Defaults to
   110    10\.
   111  
   112  - All [planning modes](/cli/commands/plan#planning-modes) and
   113  [planning options](/cli/commands/plan#planning-options) for
   114  `terraform plan` - Customize how Terraform will create the plan. Only available when you run `terraform apply` without a saved plan file.
   115  
   116  For configurations using
   117  [the `local` backend](/language/settings/backends/local) only,
   118  `terraform apply` also accepts the legacy options
   119  [`-state`, `-state-out`, and `-backup`](/language/settings/backends/local#command-line-arguments).
   120  
   121  ## Passing a Different Configuration Directory
   122  
   123  Terraform v0.13 and earlier also accepted a directory path in place of the
   124  plan file argument to `terraform apply`, in which case Terraform would use
   125  that directory as the root module instead of the current working directory.
   126  
   127  That usage was deprecated in Terraform v0.14 and removed in Terraform v0.15.
   128  If your workflow relies on overriding the root module directory, use
   129  [the `-chdir` global option](/cli/commands/#switching-working-directory-with-chdir)
   130  instead, which works across all commands and makes Terraform consistently look
   131  in the given directory for all files it would normally read or write in the
   132  current working directory.
   133  
   134  If your previous use of this legacy pattern was also relying on Terraform
   135  writing the `.terraform` subdirectory into the current working directory even
   136  though the root module directory was overridden, use
   137  [the `TF_DATA_DIR` environment variable](/cli/config/environment-variables#tf_data_dir)
   138  to direct Terraform to write the `.terraform` directory to a location other
   139  than the current working directory.