- Lab
- A Cloud Guru
Migrating Terraform State to Terraform Cloud
Hey there, Gurus! Welcome to the lab! In this lab, you will migrate your local Terraform state to Terraform Cloud for better collaboration between you and your trusty team. You will create and configure a Terraform Cloud workspace, where you will store your state for your EC2 instance remotely. Then, you will add a backend configuration to your Terraform configuration file and apply the updated configuration.
Path Info
Table of Contents
-
Challenge
Set Up the Environment
-
In the terminal, once logged into your instance, change to the
lab-migrate-state
directory. -
Apply the Terraform configuration.
-
In the AWS Management Console, navigate to the cloud_user in IAM and generate your Access key ID and Secret access key values.
-
Copy or download your key to use during the Terraform Cloud setup.
-
-
Challenge
Set Up Your Terraform Cloud Workspace
-
Navigate to Terraform Cloud at https://app.terraform.io/session and create a free account (or log in if you have an existing account).
-
Create an organization named ACG-Terraform-Labs.
-
Create a workspace named labs-migrate-state using the CLI-driven workflowoption.
-
Navigate to the Variables tab and add two environment variables: one named AWS_ACCESS_KEY_ID with a value of your Access key ID and one named AWS_SECRET_ACCESS_KEY with a value of your Secret access key.
-
Navigate to User Settings and then Tokens, and create an API token called terraform_login.
-
Copy your API token.
-
-
Challenge
Add the Backend Configuration
-
Log in to Terraform Cloud with the API token.
-
Add the backend block provided to the configuration file.
-
Initialize your working directory.
-
Delete your
terraform.tfstate
file.
-
-
Challenge
Apply the Updated Configuration and Confirm the State Was Saved to Terraform Cloud
-
Apply your updated configuration.
-
Confirm your state is saved to Terraform Cloud.
-
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.