Configure a Remote Backend in Terraform

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Hey there, Gurus! Welcome to the lab! This lab will demonstrate how to set up Terraform to use remote state. We will first set up our S3 bucket where we want to store our state file. We will then set up a locking table in DynamoDB, then we will create our remote backend configuration and deploy our resources. We will then end the lab by checking to make sure our state file was written to our S3 bucket successfully. Let’s get started!

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Environment Setup
  1. Log in to your lab provided AWS Management Console.
  2. Create an S3 bucket called twinkiestatebucket<RANDOM_NUMBER>.
  3. Create a DynamoDB table called terraformstatelock with a partition key named LockID.
  4. In the terminal, once logged in to your instance, change to the Remote_State directory.
Add Backend Configuration
  1. In the Remote_State directory, edit the file and add in your S3 bucket name, region, and DynamoDB table name.
  2. In the Remote_State directory, edit the file and add your Subnet ID.
  3. Initialize your working directory.
  4. Deploy your resources.
Confirm Remote Backend Status
  1. Check your working directory for the state file.
  2. Check your S3 bucket for your state file.

Additional Resources

You are an admin who supports one of the largest online comic book retailers in the world. You are one of a handful of admins who have been assigned to use Terraform to manage the company's cloud deployments. You are being asked to start to create a new dev environment to test out new features of the company's site. You are being asked to just set up something basic so you can then add to it as more details come through. The one thing you know from the ticket is that they are wanting your team to manage the infrastructure, so you know you must create the backend for the state to be stored. You already have a basic configuration that you cooked up a while back that would be perfect, you just need to add the backend to the configuration. Add the required backend to the lab configuration and deploy your infrastructure to complete this lab.

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?