Create a Terraform Configuration for Multi-Cloud Use

1.25 hours
  • 5 Learning Objectives

About this Hands-on Lab

In this lab, you will create a multi-cloud Terraform configuration that can deploy an EC2 instance and/or an Azure VM. These instances are the same resource type with the same image (Ubuntu 18.04 LTS). You will use modules, variables, and outputs to accomplish this deployment. You should be able to choose which cloud environment you would like to deploy the resources to and even do the deployment simultaneously.

**_Note:_** In order to complete this lab, you will need to spin up an Azure sandbox from our Cloud Playground once the lab starts.

Link to Cloud Playground:
https://learn.acloud.guru/cloud-playground/cloud-sandboxes

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the Terraform Project

In the AWS Console

  1. Create the AWS access key and secret access key for the cloud_user.

In the Terminal

  1. Configure the AWS CLI with your credentials.
  2. Configure the Azure CLI.
  3. Create the eightbit_studios directory with a modules directory containing the aws_instance and azure_instance directories.
  4. Create the providers.tf file in the Terraform working directory eightbit_studio with the AWS and Azure providers.
  5. Initialize the eightbit_studio working directory.
Create the AWS Module
  1. Create the aws_instance.tf Terraform configuration file that declares the resources necessary to create multiple EC2 instances in the .modules/aws_instance directory.
  2. Create the variables.tf Terraform configuration file that declares the variables necessary for the AWS module in the .modules/aws_instance directory. These variables should include instances, subnet, ami id, and instance type.
  3. Create the outputs.tf Terraform configuration file that declares the output necessary to output the AWS instance names for the AWS module in the .modules/aws_instance directory.
Create the Azure Module
  1. Create the azure_instance.tf Terraform configuration file that declares the resources necessary to create multiple Virtual Machines in the .modules/azure_instance directory.
  2. Create the variables.tf Terraform configuration file that declares the variables necessary for the Azure module in the .modules/azure_instance directory. These variables should include instances, resource group name, and resource group location.
  3. Create the outputs.tf Terraform configuration file that declares the output necessary to output the Azure instance names for the Azure module in the .modules/azure_instance directory.
Create the Root Module
  1. Create the main.tf Terraform configuration file in the 8bit_studio working directory that declares both modules. This root module should be able to pass an enable/disable selector, the number of instances, and the subnet to the AWS module, as well as pass the resource group name and resource group location to the Azure module.
  2. Create the variables.tf Terraform configuration file that declares the variables necessary for the root module in the 8bit_studio working directory. These variables should include the enable_aws and enable_azure variable for each, instance_count, aws subnet, and the Azure resource group name and location.
  3. Create the outputs.tf Terraform configuration file that declares the outputs necessary to output the AWS instance names and the Azure instance names.
Deploy and Verify
  1. Initialize the Terraform working directory again to pull in the module information.
  2. Import the Azure resource group into your Terraform state.
  3. Deploy three EC2 instances to AWS and three VMs to Azure simultaneously.
  4. Verify that all instances have been deployed.

Additional Resources

You are working for a company called 8bit Studios as a DevOps engineer. The company started to implement Terraform in order to deploy and manage resources in their AWS environment, but they also want to start setting up and using their Azure environment as a backup to the main production environment for disaster recovery and outage purposes.

The higher-ups are not fully convinced that Terraform can handle multi-cloud as well as advertised and would like to see a demonstration of how it can be used to deploy similar resources easily between the two environments before making the push. They are hoping Terraform is the tool to help get them to their goal (i.e., to have their application and services in a multi-cloud environment) with minimal effort. It is your job to prove that Terraform is the tool to get the company to that multi-cloud dream with ease!

You will first create the 8bit_studio Terraform project directory and make it the Terraform working directory. You will then create your configuration and use modules that you need to create (called aws and azure) that will deploy three EC2 instances to AWS and three Azure VMs in Azure simultaneously with one apply.

Note: In order to complete this lab, you will need to spin up an Azure sandbox from our Cloud Playground once the lab starts.

Link to Cloud Playground: https://learn.acloud.guru/cloud-playground/cloud-sandboxes

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?