
Explore the origins and purpose of TerraForm as an infrastructure as code tool, how TerraForm works, the TerraForm registry and providers, and guided installs on macOS and Linux.
Learn how terraform works as infrastructure as code, using providers to manage resources via API calls from hcl configuration files with a .tf extension, where resources have arguments and attributes.
Learn the difference between infrastructure as code and configuration management: Terraform provisions resources without installing software, while Ansible, Chef, and Puppet configure and manage software inside those resources.
Install Terraform on macOS by downloading the official binary, unzipping, creating a home bin directory, exporting the PATH in the bash profile, and verifying the install with terraform version.
install terraform on linux uses same steps as mac. download the zip from terraform.io, unzip it, create a bin folder in your home, export path, and source your bash profile.
Choose a code editor for Terraform, with Visual Studio Code favored for its Hashicorp Terraform extension and Anton extension, plus autocompletion and IntelliSense, while Atom is sunset.
Review the basics of terraform as infrastructure as code, its registry and provider types, and the installation steps for macOS and Linux, plus how it differs from configuration management tools.
Explore the Terraform configuration file syntax, including the .tf extension, blocks with opening and closing brackets, and pound sign comments that define declarative configurations and high-level behavior.
Define Terraform version constraints using the special configuration block, choosing equal, greater-than-equal, less-than, or tilde operators, while keeping values as constants and avoiding variables.
Discover how to save keystrokes by aliasing terraform in your bash profile, using t as a shortcut, and sourcing the file to access t version commands instantly.
Explore Terraform basics by defining the root module in main.tf, recognizing the .tf extension, and using the T alias with validate, fmt, and init to manage configurations.
Explore how to configure the AWS provider in Terraform using the official provider from the registry. Learn how to use provider blocks, examples, and initialization for Terraform 0.13 and later.
Initialize the AWS provider, remove the duplicate Terraform block, and relax the version constraint with tilde to 4.99; Terraform creates a hidden providers folder and binary for API calls.
Run the Terraform providers command to see which providers your configuration requires. Identify the AWS provider maintained by HashiCorp and its version constraint, 4.47 to 99, for this configuration.
Configure the AWS provider in Terraform to enable API calls and resource management, including creating an IAM admin user, an Admin group, and generating access and secret keys for authentication.
Create an admins group with administrator access in AWS IAM, then add user Bob with programmatic access and access keys for AWS CLI or Terraform, and secure the keys.
Understand access and secret keys as full admin credentials, like a root password. Form a public access key and private secret key that can create resources through IAM.
Review how Terraform interacts with providers to provision resources, including the AWS provider and provider plugins; configure a Kubernetes provider and IAM user with programmatic access.
Demonstrate configuring the AWS provider block and authenticating with access key and secret key, avoiding hardcoding and using shared config and profile before resource creation.
Create an AWS IAM group with Terraform by defining a resource and providing name and path, then use plan and apply to realize the desired state.
Explore the terraform state list and terraform state show commands to view and inspect resources, such as an IAM group created by configuration, without relying on the AWS management console.
Export credentials as environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION) and remove them from the provider block, then run the Terraform plan to verify resource creation.
Configure the AWS CLI with a DevOps profile, set access keys, region, and JSON output, and practice creating an IAM group for Terraform import.
Learn to supply AWS credentials via shared credential and configuration files in Terraform, configure the DevOps profile, and set the region to provision resources.
Learn how to bring existing AWS IAM groups into Terraform managed infrastructure using the Terraform import command, defining IAM group resources and importing production, staging, and development groups.
Demonstrates how a Terraform state file records version, serial, lineage, outputs, and resources, and shows how destroy cleans up resources and updates the AWS management console.
Recover a lost Terraform state file by using backups, avoid recreating resources, and import the AWS IAM user and IAM group back into state using their unique IDs or names.
Demonstrates creating an AWS IAM user in Terraform with a tags block using key value pairs for name, job, and department, then validate, plan, and apply.
Learn how provider default tags in Terraform attach common key-value pairs to every resource. See how resource-specific tags take precedence and how to apply defaults across the infrastructure.
Explore how organizations apply tagging categories—technical, automation, security, and business—to search resources, support cost reporting, and Terraform projects with cost allocation tags and tag key limitations.
Learn to export all tags for an IAM user as a Terraform output, including resource tags and provider inherited tags, using an output block.
Organize Terraform configuration files by splitting into users.tf, groups.tf, and outputs.tf, then validate and plan to see how the files merge into a state with a user and a group.
Learn to reference resource attributes in Terraform to build relationships between IAM users and the DevOps group using a membership resource that combines user and group attributes.
Create two users and a DevOps group in Terraform, then define IAM group membership by referencing resource attributes. Apply and destroy steps demonstrate plan, apply, and verification of group membership.
Execute Terraform destroy to terminate all resources managed by Terraform, updating the state file and leaving unmanaged resources untouched; use caution, as this irreversible action can affect production environments.
Define a Terraform variable named user_name for the IAM user and reference it as var.user_name with type string and a default value of David.
Use the Terraform console to inspect variables, pull list items by zero-based indices, and validate, plan, and apply with auto-approve to create three users.
Pass a list of input values from the command line into Terraform using -var with a string list, replacing defaults with usernames like Bobby, Johnny, and Tony, then apply.
Master Terraform list operations by using sort, reverse, and element to manipulate lists, understand circular indexing, and prepare for refactoring with count in assignments.
Learn how the Terraform count meta argument creates multiple similar resources, using count.index to distinguish each instance, enabling separate update, delete, and management of IAM users or other resource types.
Explore using a map variable type in Terraform to assign each user to an internal or external team, and use dot notation to access map elements.
Explore how to use the splat expression in Terraform to pull attributes from multiple similar resources, such as IAM users, in one command.
Investigate how Terraform uses the splat expression or the for expression to produce a list output from a list of users and access attributes like user.name.
Clean up the current terraform infrastructure by destroying three iam users and confirming the state is empty. Prepare for a fresh project.
Explore Terraform variables and types, including list and map, with input via --var and tfvars files, and cover count, index, list functions, and splat expressions.
Build the network stack by creating the initial Terraform files: outputs, providers AWS, terraform.tfvars, variables.tf, and a VPC config, then begin the first VPC step by step.
Initialize the Terraform project by configuring the AWS provider in providers.tf, validate, format, and initialize, then run a plan to confirm no resources exist before creating them.
Learn to streamline AWS interactions by creating shortcuts and favorites for frequently used services. Star services like VPC to keep them in the favorites bar for quicker access.
Create your first AWS VPC, a virtual private cloud with an IPv4 CIDR block like 172.31.0.0/16 and a default VPC. Understand the VPC dashboard, IPv4, IPv6, and DHCP options basics.
Learn how manually creating a VPC in the provider console reveals Terraform's required arguments, such as a name tag and an IPv4 CIDR block, for accurate provisioning.
Create your first AWS VPC using Terraform, defining a 192.168.0.0/16 IPv4 CIDR, enabling DNS hostname and DNS domain, and applying default lab tags with a VPC CIDR output.
Create an AWS VPC with Terraform by copying a provider example, configure the CIDR block and tags, validate, apply with auto-approve, and inspect the resulting VPC.
Implement an internet gateway with Terraform by creating the resource, setting tags and names from variables, attaching it to a VPC, and validating with plan and apply.
Create a subnet in your VPC by specifying the VPC id and a cidr block, with an optional name tag and a chosen availability zone for your Terraform setup.
Refactor Terraform code into a single subnet resource using the count meta argument and list variables. Create two public and two private subnets efficiently without duplication.
Learn how to refactor Terraform subnet creation by using a single resource with the count meta-argument, driven by lists of CIDR blocks, AZs, and public IP flags.
Learn how AWS route tables govern cross-subnet and internet communication, with rules mapping destinations to targets, distinguishing public and private subnets, and configuring routes in Terraform.
build a terraform route table for a vpc, add a route to the internet via an igw, and validate, plan, and apply the configuration.
Explore how Terraform data sources work with AWS, retrieve VPC information using data aws_vpc, and use the CIDR block and ID outputs to feed subsequent resources such as subnets.
Prepare the VPC data source demo by creating a vpc.tf in a temp directory. Add a minimal Terraform configuration to initialize the AWS provider and run terraform init.
Learn how to use Terraform data sources to retrieve AWS VPC information, such as CIDR blocks and VPC IDs, by querying with CIDR or ID and exposing outputs.
Retrieve vpc information using terraform data sources and outputs, tagging with dns port and owner id. Apply filters to identify public subnets for final associations.
Learn to fetch all subnet IDs within a VPC using the AWS subnets data source, with optional filters or tags and VPC ID filtering.
Filter public subnets using a tags filter with a wildcard to match 'public' in the subnet name tag. Retrieve public subnet IDs via a data source, then validate and plan.
Destroy the network stack with terraform destroy to remove all resources, including the internet gateway, subnets, route tables, the VPC, and the nat gateway.
Initialize the project by creating a compute folder with Terraform files (variables.tf, outputs.tf, ssh_keys.tf, security_group.tf, ec2.tf), bring in providers, and run terraform init.
Use Terraform plan and apply with a target to limit work to a specific resource, such as the AWS VPC main_vpc, creating the VPC first then subnets and associations.
Create an AWS key pair resource with Terraform by importing a public SSH key, ensure supported formats (ed25519 or 2048-bit), and export the key name via variables for deployment.
Learn how security groups protect a resource within a VPC with inbound and outbound rules, enabling ssh and http access from the internet, and implement these in Terraform.
Enforce a lifecycle policy on security group resources to create before destroy, preventing hung deletions when renaming a security group and avoiding replacement during plan.
Master the for each meta argument and its relation to count. Create instances for each item in a map or set of strings using each.key, each.value, or index.
Demonstrates using the for_each meta argument with a set of strings in Terraform to create IAM users, comparing count index and each.value based naming.
Demonstrate using the for each meta-argument with a map variable to create two IAM users, using each.value as the name for Shama and Sitaram.
Rewrite the security group with a single dynamic ingress block built from a set of map objects, replacing two ingress blocks, while preserving the separate egress block and CIDR rules.
Provision an aws ec2 instance with terraform by selecting an ami, adding a name tag, and dynamically resolving region-specific ami ids to avoid hardcoding, security group and key pair included.
Learn to obtain the latest amazon linux ami with the aws_ami data source in Terraform, using owners and filters to avoid hardcoding for EC2 provisioning.
Create a aws ec2 instance with terraform using data sources from data.tf for emi and vpc in public subnet 1a with a variable instance type, and output its public ip.
Create an ec2 instance with terraform by configuring the name and type, using vpc and ami data sources, and applying to obtain the web server's public ip.
Use a Terraform local-exec provisioner inside an EC2 resource to write the instance name and private IP to a local file, and continue on failure without tainting the resource.
Demonstrates using terraform's file provisioner to copy a script to an ec2 host via ssh, configuring source and destination, with timeout handling and continued execution on failure.
Explore how Terraform state shows null resources used by provisioners. Learn that local provisioners attached to a null resource run only once, at initial creation.
Learn how to extend a web server's storage with EBS volumes, choosing gp3 over gp2, configuring size, IOPS, throughput, and availability zone, and attaching volumes via manual steps and Terraform.
Create two AWS EBS volumes in Terraform, each 1 GB gp3 with 3000 IOPS and 125 throughput, in the same availability zone as EC2, tagged web and data.
Define a Terraform variables.tf EBS volumes list to provision two GP3 volumes with 3000 IOPS and 125 throughput, tagged web and data, and prepare for EC2 attachment.
Attach two EBS volumes to an EC2 instance with Terraform using a volume_attachment resource, specifying device names, instance ID, and volume ID, and selecting available dev names.
Create aws volume attachment resources in terraform for multiple ebs volumes, bind them to the ec2 instance using count and device names, then apply to attach and verify.
Practice safe cloud teardown by destroying EC2 instances, EBS volumes, security groups, and SSH key pairs using Terraform, ensuring all resources are cleanly removed.
Course Overview
Welcome to this amazing course on Terraform where you will learn how to manage your infrastructure as a code. Terraform is one of the most popular tool of choice for DevOps Engineers because it is platform agnostic, it can work with any provider either it would be GCP, Microsoft Azure, AWS, Kubernetes, Docker, etc.
You will learn how to interact with all of these providers, how to create resources, and how to automate managing the Infrastructure as a Code(IaC) using Terraform and much more!
Course Sections
Section 1: Course Introduction
Section 2: Terraform Introduction
Section 3: Terraform Basics
Section 4: AWS Provider Basics
Section 5: Providers Authentication & Configuration
Section 6: AWS CLI
Section 7: Terraform Building Blocks
Section 8: Terraform Variables
Section 9: Terraform and AWS - Network Stack Project
Section 10: Terraform and AWS - EC2 Web Server Project
Section 11: Terraform and DigitalOcean
Section 12: Terraform and Docker
Section 13: Terraform Modules
Section 14: Managing Terraform State
Section 15: Terraform and Kubernetes
Section 16: Course Completion
Course Updates
Note: The sections of this course are not static, there will be constant updates to all the sections, we will be adding more sections, more lessons to existing sections, on a monthly basis.
Course Updates January 2025
Note: I will be re-shuffling this course by adding more new lessons and archiving some older lessons.
Course Updates April 2025
Note: Following lessons were added:
* Installing Terraform on Ubuntu
* Installing Terraform on Amazon Linux 2023
* Upgrading Terraform