Managing Applications and Infrastructure with Terraform

Course

April 30th, 2018

Intro Video

Photo of Derek Morgan

Derek Morgan

Training Architect

Length

13:04:56

Difficulty

Intermediate

Course Details

This course will take you from the basics of Terraform to more advanced deployments that will allow you to create masterful Terraform deployments of your own involving Docker, AWS, Kubernetes, and other technologies that are capable of utilizing the benefits of Infrastructure as Code or IaC.

Syllabus

Introduction

Introduction

Course Introduction

00:02:56

Lesson Description:

In this lesson, you are introduced to the course, the prerequisites, and what you can expect to gain!

About the Author

00:00:40

Lesson Description:

Meet Derek! The author of this Managing Applications and Infrastructure with Terraform course!

Linux Academy Tools

00:02:37

Lesson Description:

In this lesson, we will cover the various tools available to Linux Academy students. 

About Terraforrm

00:04:40

Lesson Description:

In this lesson, we will cover the basics of Terraform and the problems it solves. 

Deploying Infrastructure with Terraform

Terraform Basics and a Docker Deployment

Workstation Setup

00:09:32

Lesson Description:

In this lesson, we will walk through the configuration of our workstation in order to get it up and running for our Terraform Docker deployments. NOTE: The Cloud Playground has changed. Create an Ubuntu 16.04 server and connect using the details provided in the new Cloud Playground. After connecting, change to root with a: sudo -i https://support.linuxacademy.com/hc/en-us/articles/360018147031-Create-a-New-Cloud-Playground-Server https://support.linuxacademy.com/hc/en-us/articles/360019096651-Cloud-Playground-FAQ AFTER you have set up your server, skip to 2:31 in the video. To install Terraform 0.11.5: sudo curl -O https://releases.hashicorp.com/terraform/0.11.5/terraform_0.11.5_linux_amd64.zip sudo apt-get install unzip sudo mkdir /bin/terraform sudo unzip terraform_0.11.5_linux_amd64.zip -d /usr/local/bin/ To install Docker CE: sudo apt-get update sudo apt-get install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update sudo apt-get install docker-ce=18.06.1~ce~3-0~ubuntu

Your First Script

00:06:21

Lesson Description:

In this lesson, we are going to deploy our very first infrastructure. We will learn about Terraform resources and start exploring Terraform syntax and console commands. Please use Terraform 0.11.5 to complete this lesson sudo curl -O https://releases.hashicorp.com/terraform/0.11.5/terraform_0.11.5_linux_amd64.zip sudo apt-get install unzip sudo mkdir /bin/terraform sudo unzip terraform_0.11.5_linux_amd64.zip -d /usr/local/bin/

Interpolation Syntax

00:08:49

Lesson Description:

In this lesson, we will learn about Terraform's interpolation syntax and deploy a container from our Docker image. 

Tainting and Updating Resources

00:06:09

Lesson Description:

In this lesson, we are going to take a look at how to force a redeploy of your resources using tainting. This is an extremely useful skill for when parts of a deployment need to be modified.

Terraform Console and Output

00:06:30

Lesson Description:

In this lesson, we will use the Terraform Console to view various Outputs that we can use for our scripts. The Terraform Console is extremely useful for troubleshooting and planning deployments.

Terraform Variables

00:05:29

Lesson Description:

In this lesson, we are going to improve our scripts and make them more portable by adding variables. These variables will prove to be very useful when using the same scripts for multiple deployments.

Breaking Out Our Variables and Outputs

00:03:58

Lesson Description:

In this lesson, we will pull our variables and outputs from our main.tf file for a more stateless deployment. By separating the variables and outputs from our main file, this will allow us to deploy different environments by interchanging those files with files that contain different values.

Introduction to Modules

00:03:01

Lesson Description:

In this lesson, we are going to take a look at one of the core abilities of Terraform by using modules. Modules allow us to modify our deployments by including only the pieces of the deployment we require. Due to the number of files involved with the following videos, I am only able to link to the repository. Github

Modules - The Image Module

00:05:40

Lesson Description:

We are going to break our image resource into a module, which will allow us to customize our deployments by choosing to include or not include this module.  Due to the number of files involved with the following videos, I am only able to link to the repository. Github

Modules - The Container Module

00:06:05

Lesson Description:

In this lesson, we create our container module which will allow us to customize our deployments by choosing to include or not include this module.   Github

Modules - The Root Module

00:13:00

Lesson Description:

We will create the main.tf at the root of the application. This file will control which modules are deployed within our environment.  Github

Maps and Lookups

00:13:15

Lesson Description:

In this lesson, we will create a Map to specify different environment variables based on conditions. This will allow us to dynamically deploy infrastructure configurations based on information we pass to the deployment.  Github

Terraform Workspaces

00:05:57

Lesson Description:

In this lesson, we will see how workspaces can help us deploy multiple environments. By using workspaces, you can deploy multiple environments simultaneously without the state files colliding. Github

Breaking Out Our Variable Definitions

00:06:46

Lesson Description:

In this lesson, we will create our tfvars file that will hold our variable definitions. By separating our variable definitions, we will be able to improve security by not storing those variable definitions in source control. Github

Null Resources and Local-Exec

00:04:42

Lesson Description:

In this lesson, we will utilize a "Null Resource" in order to perform local commands on our machine without having to deploy extra resources.  Github

QUIZ: Terraform for Docker

00:45:00

Terraform for AWS

AWS and Cloud9 Setup

00:06:50

Lesson Description:

In this lesson, we will walk through setting up the AWS environment. This environment will have all of the permissions necessary to deploy our infrastructure. Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Terraform Install on Cloud9

00:01:34

Lesson Description:

In this lesson, we will install Terraform on our Cloud9 workstation so that we can continue through our deployment. To install Terraform 0.11.5: sudo curl -O https://releases.hashicorp.com/terraform/0.11.5/terraform_0.11.5_linux_amd64.zip sudo apt-get install unzip sudo mkdir /bin/terraform sudo unzip terraform_0.11.5_linux_amd64.zip -d /usr/local/bin/ Due to the complexity of the AWS infrastructure we are going to deploy and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Our Architecture - What We're Going to Build

00:04:29

Lesson Description:

In this lesson, we will walk through a diagram of the resources we will deploy throughout this course.   LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Storage Part 1: The S3 Bucket and Random ID

00:08:54

Lesson Description:

In this lesson, we will start our Terraform and AWS journey by creating an S3 bucket. Due to AWS requiring all S3 Buckets to be globally unique, we will use the Random ID resource to create a random ID that we will append to our S3 Bucket. This will provide entropy and ensure our S3 Bucket deploys successfully. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Storage Part 2: The Root Module

00:08:34

Lesson Description:

In this lesson, we continue our S3 deployment by adding it to the root/main.tf file.   LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Networking Part 1 : VPC, IGW, and Route Tables

00:14:00

Lesson Description:

In this lesson, we will start our networking resource deployment and we will deploy our Internet Gateway and route tables. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Networking Part 2: Subnets, Security, and the Count Attribute

00:18:35

Lesson Description:

In this lesson, we continue our networking resource deployment, and we configure our route table. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Networking Part 3: The Root Module

00:06:54

Lesson Description:

In this lesson, we will finish our networking deployment and add the networking module to our root module.  LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Compute Part 1 - AMI Data, Key Pair, and the File Function

00:12:04

Lesson Description:

In this lesson, we will start to script our compute resources. We will create a key to use for access to our EC2 instance and explore the "file" function. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github IMPORTANT if you are following along with this lesson by typing in the code as is, you will need to do a slight alteration. When defining server_ami replace filter { name = "owner-alias" values = ["amazon"] } with owners = ["amazon"]

Compute Part 2: The EC2 Instance

00:07:24

Lesson Description:

In this lesson, we are going to continue our compute deployment, and we will create our EC2 Instance. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Compute Part 3: User Data and Template Files

00:11:15

Lesson Description:

In this lesson, we continue deploying our compute resources and work toward a full EC2 deployment. We will create our userdata using a template file. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Compute Part 4: The Root Module

00:18:35

Lesson Description:

In this lesson, we finish scripting our compute resources and add our resources to the root module allowing us to finally deploy. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Terraform Apply and Troubleshooting

00:08:02

Lesson Description:

In this lesson, we finally run the Terraform Apply. We also encounter a little trouble on the way, so we will troubleshoot those errors and deploy our resources! This lesson will provide valuable troubleshooting skills for Terraform deployments. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Outputs and the Join Function

00:08:08

Lesson Description:

In this lesson, we will enhance our script using Outputs and the "Join" function. The Join function will allow us to format our outputs to provide a more user-friendly display. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Terraform Formatting and Remote State

00:10:50

Lesson Description:

In this lesson, we are going to learn how to format our files automatically using "terraform fmt". We will then learn how to secure our infrastructure state by exporting it to an external location. LucidChart Link Due to the complexity of the AWS infrastructure we are going to deploy, and the number of files involved, I will only be providing the full Github Repo for reference as opposed to stages. Github

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

00:30:00

QUIZ: Terraform for AWS

00:45:00

Terraform and Kubernetes

Setup

00:06:14

Lesson Description:

In this lesson, we configure the provider for our cluster. This will be the first step of our deployment. kubeadm init --pod-network-cidr=10.244.0.0/16 mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml kubectl taint nodes --all node-role.kubernetes.io/master-

Deploy a Container

00:04:33

Lesson Description:

In this lesson, we deploy a container to our cluster. Although it is a simple deployment, it will set the foundation for much larger Kubernetes deployments using Terraform.

QUIZ: Terraform for Kubernetes

00:45:00

Conclusion

Conclusion

What's Next?

00:01:37

Lesson Description:

In this lesson, we will look at some opportunities for next courses.