- Lab
- A Cloud Guru
Migrate an Existing Terraform Project into Terraform Cloud
In this hands-on lab, we will take an existing Terraform configuration and convert it to run the code using Terraform Cloud. We will use the CLI-driven method to deploy our resources to AWS with Terraform Cloud doing the bulk of the work.
Path Info
Table of Contents
-
Challenge
Prepare the Environment
-
Log in to the lab instance.
-
Clone the lab repo to your lab machine:
git clone https://github.com/ACloudGuru-Resources/content-introduction-terraform-cloud-lab.git
-
Create the
terraform-guru
organization. -
Select CLI-driven workflow.
-
Create the
terraform-cloud-guru
workspace. -
Create a variable set by going to your workspace settings and then Variable sets. Click Create variable set.
-
Use
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
environment variables. -
In the AWS Management Console, create an access key for the
cloud_user
and secret access key, and use those values for the variable set. -
In the user settings, create a token for the CLI to use with Terraform Cloud called
terraform-cloud
. You must copy the key, runterraform login
in your terminal, and follow the prompts.
-
-
Challenge
Migrate the Existing Terraform Project into Terraform Cloud
- Modify the
main.tf
file, and add the Terraform Cloud config. - Add the Terraform variables in Terraform Cloud for your workspace for the
ami
,instance_count
,instance_type
, andsubnet
Note: You will need to look this up from the console or CLI. All other variables will be in the
variables.tf
file. - Modify the variables so they use the Terraform Cloud variables.
- Modify the
-
Challenge
Deploy the EC2 Instances with Terraform Cloud
- Initialize your working directory.
- Validate your code.
- Apply your configuration, and view it in your terminal and Terraform Cloud Runs section.
- Check the AWS Management Console to verify the instances were created.
-
Challenge
Create a Terraform Module from Existing Code
- Create a GitHub repo called
terraform-as-ec2-psacg
. - Add the Terraform Cloud application, and configure it.
- Add the module configuration to your repo called
main.tf
. - Add a tag to the repo of
1.0.0
. - Add the module to Terraform Cloud Registry.
- Create a GitHub repo called
-
Challenge
Modify the Terraform Configuration to use the Module and Redeploy
- Edit the main Terraform configuration to use the module.
- Initialize the Terraform working directory.
- Validate the syntax.
- Apply your new configuration.
- Confirm the changes.
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.