terraform/website/source/intro/getting-started/remote.html.markdown

87 lines
3.9 KiB
Markdown
Raw Normal View History

---
layout: "intro"
page_title: "Terraform Remote"
sidebar_current: "gettingstarted-remote"
description: |-
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.
---
# Why Use Terraform Remotely?
We've now seen how to build, change, and destroy infrastructure
from a local machine. This is great for testing and development,
however in production environments it is more responsible to run
Terraform remotely and store a master Terraform state remotely.
2015-04-21 00:32:59 +02:00
[Atlas](https://atlas.hashicorp.com/?utm_source=oss&utm_medium=getting-started&utm_campaign=terraform),
HashiCorp's solution for Terraform remote, runs an
2015-04-21 00:32:59 +02:00
infrastructure version control. Running Terraform
in Atlas allows teams to easily version, audit, and collaborate
on infrastructure changes. Each proposed change generates
a Terraform plan which can be reviewed and collaborated on as a team.
When a proposed change is accepted, the Terraform logs are stored
in Atlas, resulting in a linear history of infrastructure states to
help with auditing and policy enforcement. Additional benefits to
running Terraform remotely include moving access
credentials off of developer machines and releasing local machines
from long-running Terraform processes.
# How to Use Terraform Remotely
2015-04-21 00:41:46 +02:00
You can learn how to use Terraform remotely with our [interactive tutorial](https://atlas.hashicorp.com/tutorial/terraform/?utm_source=oss&utm_medium=getting-started&utm_campaign=terraform)
2015-04-21 00:32:59 +02:00
or you can follow the outlined steps below.
First, If you don't have an Atlas account, you can [create an account here](https://atlas.hashicorp.com/account/new?utm_source=oss&utm_medium=getting-started&utm_campaign=terraform).
In order for the Terraform CLI to gain access to your Atlas account you're going to need to generate an access key. From the main menu, select your username in the left side navigation menu to access your profile. Under `Personal`, click on the `Tokens` tab and hit generate.
Update remote.html.markdown these changes were added to reflect what was required to run the tutorial on my local machine. Below is my context for the above changes: ```shell [2016-03-04T18:22:44] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" missing 'access_token' configuration or ATLAS_TOKEN environmental variable If the error message above mentions requiring or modifying configuration options, these are set using the `-backend-config` flag. Example: -backend-config="name=foo" to set the `name` configuration [2016-03-04T18:23:27] micperez in terraform_test λ export ATLAS_TOKEN=<REDACTED> [2016-03-04T18:24:12] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" Remote state management enabled Remote state configured and pulled. [2016-03-04T18:24:16] micperez in terraform_test λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error detecting VCS: no VCS found for path: /Users/micperez/code/terraform_test [2016-03-04T18:24:39] micperez in terraform_test λ git init Initialized empty Git repository in /Users/micperez/code/terraform_test/.git/ [2016-03-04T18:25:09] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error getting git commit: exit status 128 stdout: stderr: fatal: bad default revision 'HEAD' [2016-03-04T18:25:12] micperez in terraform_test [git:master] λ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) .terraform/ example.tf terraform.tfstate.backup nothing added to commit but untracked files present (use "git add" to track) [2016-03-04T18:25:17] micperez in terraform_test [git:master] λ git add example.tf [2016-03-04T18:25:24] micperez in terraform_test [git:master] λ git commit -m "init commit" [master (root-commit) 34c4fa5] init commit 1 file changed, 10 insertions(+) create mode 100644 example.tf [2016-03-04T18:25:32] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" Uploading Terraform configuration... Configuration "puhrez/getting-started" uploaded! (v1) ```
2016-03-05 00:42:32 +01:00
For the purposes of this tutorial you can use this token by exporting it to your local shell session:
```
$ export ATLAS_TOKEN=ATLAS_ACCESS_TOKEN
```
Update remote.html.markdown these changes were added to reflect what was required to run the tutorial on my local machine. Below is my context for the above changes: ```shell [2016-03-04T18:22:44] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" missing 'access_token' configuration or ATLAS_TOKEN environmental variable If the error message above mentions requiring or modifying configuration options, these are set using the `-backend-config` flag. Example: -backend-config="name=foo" to set the `name` configuration [2016-03-04T18:23:27] micperez in terraform_test λ export ATLAS_TOKEN=<REDACTED> [2016-03-04T18:24:12] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" Remote state management enabled Remote state configured and pulled. [2016-03-04T18:24:16] micperez in terraform_test λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error detecting VCS: no VCS found for path: /Users/micperez/code/terraform_test [2016-03-04T18:24:39] micperez in terraform_test λ git init Initialized empty Git repository in /Users/micperez/code/terraform_test/.git/ [2016-03-04T18:25:09] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error getting git commit: exit status 128 stdout: stderr: fatal: bad default revision 'HEAD' [2016-03-04T18:25:12] micperez in terraform_test [git:master] λ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) .terraform/ example.tf terraform.tfstate.backup nothing added to commit but untracked files present (use "git add" to track) [2016-03-04T18:25:17] micperez in terraform_test [git:master] λ git add example.tf [2016-03-04T18:25:24] micperez in terraform_test [git:master] λ git commit -m "init commit" [master (root-commit) 34c4fa5] init commit 1 file changed, 10 insertions(+) create mode 100644 example.tf [2016-03-04T18:25:32] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" Uploading Terraform configuration... Configuration "puhrez/getting-started" uploaded! (v1) ```
2016-03-05 00:42:32 +01:00
Replace `ATLAS_ACCESS_TOKEN` with the token generated earlier
Then configure [Terraform remote state storage](/docs/commands/remote.html) with the command:
```
$ terraform remote config -backend-config="name=ATLAS_USERNAME/getting-started"
```
Update remote.html.markdown these changes were added to reflect what was required to run the tutorial on my local machine. Below is my context for the above changes: ```shell [2016-03-04T18:22:44] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" missing 'access_token' configuration or ATLAS_TOKEN environmental variable If the error message above mentions requiring or modifying configuration options, these are set using the `-backend-config` flag. Example: -backend-config="name=foo" to set the `name` configuration [2016-03-04T18:23:27] micperez in terraform_test λ export ATLAS_TOKEN=<REDACTED> [2016-03-04T18:24:12] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" Remote state management enabled Remote state configured and pulled. [2016-03-04T18:24:16] micperez in terraform_test λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error detecting VCS: no VCS found for path: /Users/micperez/code/terraform_test [2016-03-04T18:24:39] micperez in terraform_test λ git init Initialized empty Git repository in /Users/micperez/code/terraform_test/.git/ [2016-03-04T18:25:09] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error getting git commit: exit status 128 stdout: stderr: fatal: bad default revision 'HEAD' [2016-03-04T18:25:12] micperez in terraform_test [git:master] λ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) .terraform/ example.tf terraform.tfstate.backup nothing added to commit but untracked files present (use "git add" to track) [2016-03-04T18:25:17] micperez in terraform_test [git:master] λ git add example.tf [2016-03-04T18:25:24] micperez in terraform_test [git:master] λ git commit -m "init commit" [master (root-commit) 34c4fa5] init commit 1 file changed, 10 insertions(+) create mode 100644 example.tf [2016-03-04T18:25:32] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" Uploading Terraform configuration... Configuration "puhrez/getting-started" uploaded! (v1) ```
2016-03-05 00:42:32 +01:00
Replace `ATLAS_USERNAME` with your Atlas username.
Update remote.html.markdown these changes were added to reflect what was required to run the tutorial on my local machine. Below is my context for the above changes: ```shell [2016-03-04T18:22:44] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" missing 'access_token' configuration or ATLAS_TOKEN environmental variable If the error message above mentions requiring or modifying configuration options, these are set using the `-backend-config` flag. Example: -backend-config="name=foo" to set the `name` configuration [2016-03-04T18:23:27] micperez in terraform_test λ export ATLAS_TOKEN=<REDACTED> [2016-03-04T18:24:12] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" Remote state management enabled Remote state configured and pulled. [2016-03-04T18:24:16] micperez in terraform_test λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error detecting VCS: no VCS found for path: /Users/micperez/code/terraform_test [2016-03-04T18:24:39] micperez in terraform_test λ git init Initialized empty Git repository in /Users/micperez/code/terraform_test/.git/ [2016-03-04T18:25:09] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error getting git commit: exit status 128 stdout: stderr: fatal: bad default revision 'HEAD' [2016-03-04T18:25:12] micperez in terraform_test [git:master] λ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) .terraform/ example.tf terraform.tfstate.backup nothing added to commit but untracked files present (use "git add" to track) [2016-03-04T18:25:17] micperez in terraform_test [git:master] λ git add example.tf [2016-03-04T18:25:24] micperez in terraform_test [git:master] λ git commit -m "init commit" [master (root-commit) 34c4fa5] init commit 1 file changed, 10 insertions(+) create mode 100644 example.tf [2016-03-04T18:25:32] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" Uploading Terraform configuration... Configuration "puhrez/getting-started" uploaded! (v1) ```
2016-03-05 00:42:32 +01:00
Before you [push](/docs/commands/push.html) your Terraform configuration to Atlas you'll need to start a local version control system with at least one commit. Here is an example using `git`.
Update remote.html.markdown these changes were added to reflect what was required to run the tutorial on my local machine. Below is my context for the above changes: ```shell [2016-03-04T18:22:44] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" missing 'access_token' configuration or ATLAS_TOKEN environmental variable If the error message above mentions requiring or modifying configuration options, these are set using the `-backend-config` flag. Example: -backend-config="name=foo" to set the `name` configuration [2016-03-04T18:23:27] micperez in terraform_test λ export ATLAS_TOKEN=<REDACTED> [2016-03-04T18:24:12] micperez in terraform_test λ terraform remote config -backend-config="name=puhrez/getting-started" Remote state management enabled Remote state configured and pulled. [2016-03-04T18:24:16] micperez in terraform_test λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error detecting VCS: no VCS found for path: /Users/micperez/code/terraform_test [2016-03-04T18:24:39] micperez in terraform_test λ git init Initialized empty Git repository in /Users/micperez/code/terraform_test/.git/ [2016-03-04T18:25:09] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" An error has occurred while archiving the module for uploading: error getting git commit: exit status 128 stdout: stderr: fatal: bad default revision 'HEAD' [2016-03-04T18:25:12] micperez in terraform_test [git:master] λ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) .terraform/ example.tf terraform.tfstate.backup nothing added to commit but untracked files present (use "git add" to track) [2016-03-04T18:25:17] micperez in terraform_test [git:master] λ git add example.tf [2016-03-04T18:25:24] micperez in terraform_test [git:master] λ git commit -m "init commit" [master (root-commit) 34c4fa5] init commit 1 file changed, 10 insertions(+) create mode 100644 example.tf [2016-03-04T18:25:32] micperez in terraform_test [git:master] λ terraform push -name="puhrez/getting-started" Uploading Terraform configuration... Configuration "puhrez/getting-started" uploaded! (v1) ```
2016-03-05 00:42:32 +01:00
```
$ git init
$ git add example.tf
$ git commit -m "init commit"
```
Next, [push](/docs/commands/push.html) your Terraform configuration to Atlas with:
```
$ terraform push -name="ATLAS_USERNAME/getting-started"
```
This will automatically trigger a `terraform plan`, which you can
review in the [Environments tab in Atlas](https://atlas.hashicorp.com/environments).
If the plan looks correct, hit "Confirm & Apply" to execute the
infrastructure changes.
# Version Control for Infrastructure
Running Terraform in Atlas creates a complete history of
infrastructure changes, a sort of version control
for infrastructure. Similar to application version control
systems such as Git or Subversion, this makes changes to
infrastructure an auditable, repeatable,
and collaborative process. With so much relying on the
stability of your infrastructure, version control is a
responsible choice for minimizing downtime.
## Next
You now know how to create, modify, destroy, version, and
collaborate on infrastructure. With these building blocks,
you can effectively experiment with any part of Terraform.
Next, we move on to features that make Terraform configurations
slightly more useful: [variables, resource dependencies, provisioning,
and more](/intro/getting-started/dependencies.html).