github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/website/source/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  however in production environments it is more responsible to run
    14  Terraform remotely and store a master Terraform state remotely.
    15  
    16  Terraform supports a feature known as [remote backends](/docs/backends)
    17  to support this. Backends are the recommended way to use Terraform in
    18  a team environment.
    19  
    20  Depending on the features you wish to use, Terraform has multiple remote
    21  backend options. You could use Consul for state storage, locking, and
    22  environments. This is a free and open source option. You can use S3 which
    23  only supports state storage, for a low cost and minimally featured solution.
    24  
    25  [Terraform Enterprise](https://www.hashicorp.com/products/terraform/?utm_source=oss&utm_medium=getting-started&utm_campaign=terraform)
    26  is HashiCorp's commercial solution and also acts as a remote backend.
    27  Terraform Enterprise allows teams to easily version, audit, and collaborate
    28  on infrastructure changes. Each proposed change generates
    29  a Terraform plan which can be reviewed and collaborated on as a team.
    30  When a proposed change is accepted, the Terraform logs are stored,
    31  resulting in a linear history of infrastructure states to
    32  help with auditing and policy enforcement. Additional benefits to
    33  running Terraform remotely include moving access
    34  credentials off of developer machines and releasing local machines
    35  from long-running Terraform processes.
    36  
    37  ## How to Store State Remotely
    38  
    39  First, we'll use [Consul](https://www.consul.io) as our backend. Consul
    40  is a free and open source solution that provides state storage, locking, and
    41  environments. It is a great way to get started with Terraform backends.
    42  
    43  We'll use the [demo Consul server](https://demo.consul.io) for this guide.
    44  This should not be used for real data. Additionally, the demo server doesn't
    45  permit locking. If you want to play with [state locking](/docs/state/locking.html),
    46  you'll have to run your own Consul server or use a backend that supports locking.
    47  
    48  First, configure the backend in your configuration:
    49  
    50  ```hcl
    51  terraform {
    52    backend "consul" {
    53      address = "demo.consul.io"
    54      path    = "getting-started-RANDOMSTRING"
    55      lock    = false
    56    }
    57  }
    58  ```
    59  
    60  Please replace "RANDOMSTRING" with some random text. The demo server is
    61  public and we want to try to avoid overlapping with someone else running
    62  through the getting started guide.
    63  
    64  The `backend` section configures the backend you want to use. After
    65  configuring a backend, run `terraform init` to setup Terraform. It should
    66  ask if you want to migrate your state to Consul. Say "yes" and Terraform
    67  will copy your state.
    68  
    69  Now, if you run `terraform plan`, Terraform should state that there are
    70  no changes:
    71  
    72  ```
    73  $ terraform plan
    74  # ...
    75  
    76  No changes. Infrastructure is up-to-date.
    77  
    78  This means that Terraform did not detect any differences between your
    79  configuration and real physical resources that exist. As a result, Terraform
    80  doesn't need to do anything.
    81  ```
    82  
    83  Terraform is now storing your state remotely in Consul. Remote state
    84  storage makes collaboration easier and keeps state and secret information
    85  off your local disk. Remote state is loaded only in memory when it is used.
    86  
    87  If you want to move back to local state, you can remove the backend configuration
    88  block from your configuration and run `terraform init` again. Terraform will
    89  once again ask if you want to migrate your state back to local.
    90  
    91  ## Terraform Enterprise
    92  
    93  HashiCorp (the makers of Terraform) also provide a commercial solution which
    94  functions as a Terraform backend as well as enabling many other features such
    95  as remote apply, run history, state history, state diffing, and more.
    96  
    97  This section will guide you through a demo of Terraform Enterprise. Note that
    98  this is commercial software. If you are not interested at this time, you may
    99  skip this section.
   100  
   101  First, [create an account here](https://atlas.hashicorp.com/account/new?utm_source=oss&utm_medium=getting-started&utm_campaign=terraform) unless you already have one.
   102  
   103  Terraform uses your access token to securely communicate with Terraform
   104  Enterprise. To generate a token: select your username in the left side
   105  navigation menu, click "Accounts Settings", "click "Tokens", then click
   106  "Generate".
   107  
   108  For the purposes of this tutorial you can use this token by exporting it to
   109  your local shell session:
   110  
   111  ```
   112  $ export ATLAS_TOKEN=ATLAS_ACCESS_TOKEN
   113  ```
   114  
   115  Replace `ATLAS_ACCESS_TOKEN` with the token generated earlier. Next,
   116  configure the Terraform Enterprise backend:
   117  
   118  ```hcl
   119  terraform {
   120    backend "atlas" {
   121      name = "USERNAME/getting-started"
   122    }
   123  }
   124  ```
   125  
   126  Replace `USERNAME` with your Terraform Enterprise username. Note that the
   127  backend name is "atlas" for legacy reasons and will be renamed soon.
   128  
   129  Remember to run `terraform init`. At this point, Terraform is using Terraform
   130  Enterprise for everything shown before with Consul. Next, we'll show you some
   131  additional functionality Terraform Enterprise enables.
   132  
   133  Before you [push](/docs/commands/push.html) your Terraform configuration to
   134  Terraform Enterprise you'll need to start a local version control system with
   135  at least one commit. Here is an example using `git`.
   136  
   137  ```
   138  $ git init
   139  $ git add example.tf
   140  $ git commit -m "init commit"
   141  ```
   142  
   143  Next, [push](/docs/commands/push.html) your Terraform configuration:
   144  
   145  ```
   146  $ terraform push
   147  ```
   148  
   149  This will automatically trigger a `terraform plan`, which you can
   150  review in the [Terraform page](https://atlas.hashicorp.com/terraform).
   151  If the plan looks correct, hit "Confirm & Apply" to execute the
   152  infrastructure changes.
   153  
   154  Running Terraform in Terraform Enterprise creates a complete history of
   155  infrastructure changes, a sort of version control
   156  for infrastructure. Similar to application version control
   157  systems such as Git or Subversion, this makes changes to
   158  infrastructure an auditable, repeatable,
   159  and collaborative process. With so much relying on the
   160  stability of your infrastructure, version control is a
   161  responsible choice for minimizing downtime.
   162  
   163  ## Next
   164  You now know how to create, modify, destroy, version, and
   165  collaborate on infrastructure. With these building blocks,
   166  you can effectively experiment with any part of Terraform.
   167  
   168  We've now concluded the getting started guide, however
   169  there are a number of [next steps](/intro/getting-started/next-steps.html)
   170  to get started with Terraform.