Video by freeCodeCamp.org · taught by Derek Morgan · streamed from YouTube. All rights remain with the creator.
Lesson 2: Terraform and AWS: Building a Development Environment
About this lesson
This hands-on course by Derek Morgan teaches the basics of Terraform by building a redeployable development environment on AWS. It begins with setup: a tour of what will be built, creating a user in AWS IAM with suitable permissions, and preparing Visual Studio Code and the command-line tools on your own computer. Building then starts with the AWS provider and the terraform init command, followed by a first VPC created with terraform apply. You learn how Terraform records what it has created in its state file, and how terraform destroy removes resources. The network is completed piece by piece: a subnet that refers to the VPC, an internet gateway with tidy formatting from terraform fmt, a route table and its association with the subnet, and a security group that controls access. Next comes the server itself, using a data source to find the right machine image, a key pair for logging in and an EC2 instance. You then add a start-up script with user data and the file function, write scripts that add the new server to your SSH configuration, and run them with a provisioner and the templatefile function, and see how to replace a resource deliberately. The final part makes the configuration flexible with variables, explains the order of precedence when values are supplied in several places, uses conditional expressions to adapt to different operating systems, and prints useful values with outputs. Afterwards, read Chapter 2 of the course book, which diagrams the environment and explains each block.