github.com/simpleusd/terraform@v0.11.8-0.20180606155740-fce30c14f051/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    }
    59  }
    60  ```
    61  
    62  Please replace "RANDOMSTRING" with some random text. The demo server is
    63  public and we want to try to avoid overlapping with someone else running
    64  through the getting started guide.
    65  
    66  The `backend` section configures the backend you want to use. After
    67  configuring a backend, run `terraform init` to setup Terraform. It should
    68  ask if you want to migrate your state to Consul. Say "yes" and Terraform
    69  will copy your state.
    70  
    71  Now, if you run `terraform apply`, Terraform should state that there are
    72  no changes:
    73  
    74  ```
    75  $ terraform apply
    76  # ...
    77  
    78  No changes. Infrastructure is up-to-date.
    79  
    80  This means that Terraform did not detect any differences between your
    81  configuration and real physical resources that exist. As a result, Terraform
    82  doesn't need to do anything.
    83  ```
    84  
    85  Terraform is now storing your state remotely in Consul. Remote state
    86  storage makes collaboration easier and keeps state and secret information
    87  off your local disk. Remote state is loaded only in memory when it is used.
    88  
    89  If you want to move back to local state, you can remove the backend configuration
    90  block from your configuration and run `terraform init` again. Terraform will
    91  once again ask if you want to migrate your state back to local.
    92  
    93  ## Terraform Enterprise
    94  
    95  [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.
    96  
    97  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:
    98  
    99  - A VCS-driven workflow, in which it automatically queues plans whenever changes are committed to your configuration's VCS repo.
   100  - An API-driven workflow, in which a CI pipeline or other automated tool can upload configurations directly.
   101  
   102  For a hands-on introduction to Terraform Enterprise, [follow the Terraform Enterprise getting started guide](/docs/enterprise/getting-started/index.html).
   103  
   104  
   105  ## Next
   106  You now know how to create, modify, destroy, version, and
   107  collaborate on infrastructure. With these building blocks,
   108  you can effectively experiment with any part of Terraform.
   109  
   110  We've now concluded the getting started guide, however
   111  there are a number of [next steps](/intro/getting-started/next-steps.html)
   112  to get started with Terraform.