github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/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  The `terraform apply` command executes the actions proposed in a Terraform
    11  plan.
    12  
    13  > **Hands On:** Try the [Apply Terraform Configuration](https://learn.hashicorp.com/tutorials/terraform/apply?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) tutorial to learn how Terraform applies a configuration, how Terraform recovers from errors during apply, and common ways to use this command.
    14  
    15  ## Usage
    16  
    17  Usage: `terraform apply [options] [plan file]`
    18  
    19  
    20  
    21  ### Automatic Plan Mode
    22  
    23  When you run `terraform apply` without passing a saved plan file, Terraform automatically creates a new execution plan as if you had run [`terraform plan`](/cli/commands/plan), prompts you to approve that plan, and takes the indicated actions. You can use all of the [planning modes](/cli/commands/plan#planning-modes) and
    24  [planning options](/cli/commands/plan#planning-options) to customize how Terraform will create the plan.
    25  
    26  You can pass the `-auto-approve` option to instruct Terraform to apply the plan without asking for confirmation.
    27  
    28  !> **Warning:** If you use `-auto-approve`, we recommend making sure that no one can change your infrastructure outside of your Terraform workflow. This minimizes the risk of unpredictable changes and configuration drift.
    29  
    30  ### Saved Plan Mode
    31  
    32  When you pass a [saved plan file](/cli/commands/plan#out-filename) to `terraform apply`, Terraform takes the actions in the saved plan without prompting you for confirmation. You may want to use this two-step workflow when [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).
    33  
    34  Use [`terraform show`](/cli/commands/show) to inspect a saved plan file before applying it.
    35  
    36  When using a saved plan, you cannot specify any additional planning modes or options. These options only affect Terraform's decisions about which
    37  actions to take, and the plan file contains the final results of those
    38  decisions.
    39  
    40  ### Plan Options
    41  
    42  Without a saved plan file, `terraform apply` supports all planning modes and planning options available for `terraform plan`.
    43  
    44  -  **[Planning Modes](/cli/commands/plan#planning-modes):** These include `-destroy`, which creates a plan to destroy all remote objects, and `-refresh-only`, which creates a plan to update Terraform state and root module output values.
    45  - **[Planning Options](/cli/commands/plan#planning-options):** These include specifying which resource instances Terraform should replace, setting Terraform input variables, etc.
    46  
    47  ### Apply Options
    48  
    49  The following options change how the apply command executes and reports on the apply operation.
    50  
    51  - `-auto-approve` - Skips interactive approval of plan before applying. This
    52    option is ignored when you pass a previously-saved plan file, because
    53    Terraform considers you passing the plan file as the approval and so
    54    will never prompt in that case.
    55  
    56  - `-compact-warnings` - Shows any warning messages in a compact form which
    57    includes only the summary messages, unless the warnings are accompanied by
    58    at least one error and thus the warning text might be useful context for
    59    the errors.
    60  
    61  - `-input=false` - Disables all of Terraform's interactive prompts. Note that
    62    this also prevents Terraform from prompting for interactive approval of a
    63    plan, so Terraform will conservatively assume that you do not wish to
    64    apply the plan, causing the operation to fail. If you wish to run Terraform
    65    in a non-interactive context, see
    66    [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
    67    different approaches.
    68  
    69  - `-json` - Enables the [machine readable JSON UI][machine-readable-ui] output.
    70    This implies `-input=false`, so the configuration must have no unassigned
    71    variable values to continue. To enable this flag, you must also either enable
    72    the `-auto-approve` flag or specify a previously-saved plan.
    73  
    74    [machine-readable-ui]: /internals/machine-readable-ui
    75  
    76  - `-lock=false` - Don't hold a state lock during the operation. This is
    77    dangerous if others might concurrently run commands against the same
    78    workspace.
    79  
    80  - `-lock-timeout=DURATION` - Unless locking is disabled with `-lock=false`,
    81    instructs Terraform to retry acquiring a lock for a period of time before
    82    returning an error. The duration syntax is a number followed by a time
    83    unit letter, such as "3s" for three seconds.
    84  
    85  - `-no-color` - Disables terminal formatting sequences in the output. Use this
    86    if you are running Terraform in a context where its output will be
    87    rendered by a system that cannot interpret terminal formatting.
    88  
    89  - `-parallelism=n` - Limit the number of concurrent operation as Terraform
    90    [walks the graph](/internals/graph#walking-the-graph). Defaults to
    91    10\.
    92  
    93  - All [planning modes](/cli/commands/plan#planning-modes) and
    94  [planning options](/cli/commands/plan#planning-options) for
    95  `terraform plan` - Customize how Terraform will create the plan. Only available when you run `terraform apply` without a saved plan file.
    96  
    97  For configurations using
    98  [the `local` backend](/language/settings/backends/local) only,
    99  `terraform apply` also accepts the legacy options
   100  [`-state`, `-state-out`, and `-backup`](/language/settings/backends/local#command-line-arguments).
   101  
   102  ## Passing a Different Configuration Directory
   103  
   104  Terraform v0.13 and earlier also accepted a directory path in place of the
   105  plan file argument to `terraform apply`, in which case Terraform would use
   106  that directory as the root module instead of the current working directory.
   107  
   108  That usage was deprecated in Terraform v0.14 and removed in Terraform v0.15.
   109  If your workflow relies on overriding the root module directory, use
   110  [the `-chdir` global option](/cli/commands/#switching-working-directory-with-chdir)
   111  instead, which works across all commands and makes Terraform consistently look
   112  in the given directory for all files it would normally read or write in the
   113  current working directory.
   114  
   115  If your previous use of this legacy pattern was also relying on Terraform
   116  writing the `.terraform` subdirectory into the current working directory even
   117  though the root module directory was overridden, use
   118  [the `TF_DATA_DIR` environment variable](/cli/config/environment-variables#tf_data_dir)
   119  to direct Terraform to write the `.terraform` directory to a location other
   120  than the current working directory.