github.com/hugorut/terraform@v1.1.3/website/docs/cli/run/index.mdx (about)

     1  ---
     2  page_title: Provisioning Infrastructure - Terraform CLI
     3  description: 'Learn about commands for core provisioning tasks: plan, apply, and destroy.'
     4  ---
     5  
     6  # Provisioning Infrastructure with Terraform
     7  
     8  Terraform's primary function is to create, modify, and destroy infrastructure
     9  resources to match the desired state described in a
    10  [Terraform configuration](/language).
    11  
    12  When people refer to "running Terraform," they generally mean performing these
    13  provisioning actions in order to affect real infrastructure objects. The
    14  Terraform binary has many other subcommands for a wide variety of administrative
    15  actions, but these basic provisioning tasks are the core of Terraform.
    16  
    17  Terraform's provisioning workflow relies on three commands: `plan`, `apply`, and
    18  `destroy`. All of these commands require an
    19  [initialized](/cli/init) working directory, and all of them act
    20  only upon the currently selected [workspace](/cli/workspaces).
    21  
    22  ## Planning
    23  
    24  The `terraform plan` command evaluates a Terraform configuration to determine
    25  the desired state of all the resources it declares, then compares that desired
    26  state to the real infrastructure objects being managed with the current working
    27  directory and workspace. It uses state data to determine which real objects
    28  correspond to which declared resources, and checks the current state of each
    29  resource using the relevant infrastructure provider's API.
    30  
    31  Once it has determined the difference between the current state and the desired
    32  state, `terraform plan` presents a description of the changes necessary to
    33  achieve the desired state. It _does not_ perform any actual changes to real
    34  world infrastructure objects; it only presents a plan for making changes.
    35  
    36  Plans are usually run to validate configuration changes and confirm that the
    37  resulting actions are as expected. However, `terraform plan` can also save its
    38  plan as a runnable artifact, which `terraform apply` can use to carry out those
    39  exact changes.
    40  
    41  For details, see [the `terraform plan` command](/cli/commands/plan).
    42  
    43  ## Applying
    44  
    45  The `terraform apply` command performs a plan just like `terraform plan` does,
    46  but then actually carries out the planned changes to each resource using the
    47  relevant infrastructure provider's API. It asks for confirmation from the user
    48  before making any changes, unless it was explicitly told to skip approval.
    49  
    50  By default, `terraform apply` performs a fresh plan right before applying
    51  changes, and displays the plan to the user when asking for confirmation.
    52  However, it can also accept a plan file produced by `terraform plan` in lieu of
    53  running a new plan. You can use this to reliably perform an exact set of
    54  pre-approved changes, even if the configuration or the state of the real
    55  infrastructure has changed in the minutes since the original plan was created.
    56  
    57  For details, see [the `terraform apply` command](/cli/commands/apply).
    58  
    59  ## Destroying
    60  
    61  The `terraform destroy` command destroys all of the resources being managed by
    62  the current working directory and workspace, using state data to determine which
    63  real world objects correspond to managed resources. Like `terraform apply`, it
    64  asks for confirmation before proceeding.
    65  
    66  A destroy behaves exactly like deleting every resource from the configuration
    67  and then running an apply, except that it doesn't require editing the
    68  configuration. This is more convenient if you intend to provision similar
    69  resources at a later date.
    70  
    71  For details, see [the `terraform destroy` command](/cli/commands/destroy).