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

3.9 KiB

layout page_title sidebar_current description
intro Terraform Remote gettingstarted-remote 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.

Atlas, HashiCorp's solution for Terraform remote, runs an 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

You can learn how to use Terraform remotely with our interactive tutorial or you can follow the outlined steps below.

First, If you don't have an Atlas account, you can create an account here.

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.

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

Replace ATLAS_ACCESS_TOKEN with the token generated earlier

Then configure Terraform remote state storage with the command:

$ terraform remote config -backend-config="name=ATLAS_USERNAME/getting-started"

Replace ATLAS_USERNAME with your Atlas username.

Before you push 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.

$ git init
$ git add example.tf
$ git commit -m "init commit"

Next, push 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. 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.