github.com/rvichery/terraform@v0.11.10/website/intro/getting-started/remote.html.markdown (about)

     1  ---
     2  layout: "intro"
     3  page_title: "Terraform Remote"
     4  sidebar_current: "gettingstarted-remote"
     5  description: |-
     6    We've now seen how to build, change, and destroy infrastructure from a local machine. However, you can use Atlas by HashiCorp to run Terraform remotely to version and audit the history of your infrastructure.
     7  ---
     8  
     9  # Remote Backends
    10  
    11  We've now seen how to build, change, and destroy infrastructure
    12  from a local machine. This is great for testing and development,
    13  but in production environments it is more responsible to share responsibility
    14  for infrastructure. The best way to do this is by running Terraform in a remote
    15  environment with shared access to state.
    16  
    17  Terraform supports team-based workflows with a feature known as [remote
    18  backends](/docs/backends). Remote backends allow Terraform to use a shared
    19  storage space for state data, so any member of your team can use Terraform to
    20  manage the same infrastructure.
    21  
    22  Depending on the features you wish to use, Terraform has multiple remote
    23  backend options. You could use Consul for state storage, locking, and
    24  environments. This is a free and open source option. You can use S3 which
    25  only supports state storage, for a low cost and minimally featured solution.
    26  
    27  [Terraform Enterprise](https://www.hashicorp.com/products/terraform/?utm_source=oss&utm_medium=getting-started&utm_campaign=terraform)
    28  is HashiCorp's commercial solution and also acts as a remote backend.
    29  Terraform Enterprise allows teams to easily version, audit, and collaborate
    30  on infrastructure changes. Each proposed change generates
    31  a Terraform plan which can be reviewed and collaborated on as a team.
    32  When a proposed change is accepted, the Terraform logs are stored,
    33  resulting in a linear history of infrastructure states to
    34  help with auditing and policy enforcement. Additional benefits to
    35  running Terraform remotely include moving access
    36  credentials off of developer machines and freeing local machines
    37  from long-running Terraform processes.
    38  
    39  ## How to Store State Remotely
    40  
    41  First, we'll use [Consul](https://www.consul.io) as our backend. Consul
    42  is a free and open source solution that provides state storage, locking, and
    43  environments. It is a great way to get started with Terraform backends.
    44  
    45  We'll use the [demo Consul server](https://demo.consul.io) for this guide.
    46  This should not be used for real data. Additionally, the demo server doesn't
    47  permit locking. If you want to play with [state locking](/docs/state/locking.html),
    48  you'll have to run your own Consul server or use a backend that supports locking.
    49  
    50  First, configure the backend in your configuration:
    51  
    52  ```hcl
    53  terraform {
    54    backend "consul" {
    55      address = "demo.consul.io"
    56      path    = "getting-started-RANDOMSTRING"
    57      lock    = false
    58      scheme  = "https"
    59    }
    60  }
    61  ```
    62  
    63  Please replace "RANDOMSTRING" with some random text. The demo server is
    64  public and we want to try to avoid overlapping with someone else running
    65  through the getting started guide.
    66  
    67  The `backend` section configures the backend you want to use. After
    68  configuring a backend, run `terraform init` to setup Terraform. It should
    69  ask if you want to migrate your state to Consul. Say "yes" and Terraform
    70  will copy your state.
    71  
    72  Now, if you run `terraform apply`, Terraform should state that there are
    73  no changes:
    74  
    75  ```
    76  $ terraform apply
    77  # ...
    78  
    79  No changes. Infrastructure is up-to-date.
    80  
    81  This means that Terraform did not detect any differences between your
    82  configuration and real physical resources that exist. As a result, Terraform
    83  doesn't need to do anything.
    84  ```
    85  
    86  Terraform is now storing your state remotely in Consul. Remote state
    87  storage makes collaboration easier and keeps state and secret information
    88  off your local disk. Remote state is loaded only in memory when it is used.
    89  
    90  If you want to move back to local state, you can remove the backend configuration
    91  block from your configuration and run `terraform init` again. Terraform will
    92  once again ask if you want to migrate your state back to local.
    93  
    94  ## Terraform Enterprise
    95  
    96  [Terraform Enterprise](https://www.hashicorp.com/products/terraform/?utm_source=oss&utm_medium=getting-started&utm_campaign=terraform) is a commercial solution which combines a predictable and reliable shared run environment with tools to help you work together on Terraform configurations and modules.
    97  
    98  Although Terraform Enterprise can act as a standard remote backend to support Terraform runs on local machines, it works even better as a remote run environment. It supports two main workflows for performing Terraform runs:
    99  
   100  - A VCS-driven workflow, in which it automatically queues plans whenever changes are committed to your configuration's VCS repo.
   101  - An API-driven workflow, in which a CI pipeline or other automated tool can upload configurations directly.
   102  
   103  For a hands-on introduction to Terraform Enterprise, [follow the Terraform Enterprise getting started guide](/docs/enterprise/getting-started/index.html).
   104  
   105  
   106  ## Next
   107  You now know how to create, modify, destroy, version, and
   108  collaborate on infrastructure. With these building blocks,
   109  you can effectively experiment with any part of Terraform.
   110  
   111  We've now concluded the getting started guide, however
   112  there are a number of [next steps](/intro/getting-started/next-steps.html)
   113  to get started with Terraform.