Introduction to Infrastructure as Code with Terraform
What is Infrastructure as Code and Why is Terraform Useful?
Install Terraform on Mac, Linux, or Windows by downloading the binary or using a package manager (Homebrew or Chocolatey). Then create a Docker container locally by following a quick-start tutorial to check that Terraform installed correctly.
Lock and Upgrade Provider Versions
Manage your provider versions using the dependency lock file. Use version constraints to filter provider versions compatible with your configuration. Update your lock file to use a new provider version.
Authenticate to AWS and create an EC2 instance under the AWS free tier. Write and validate Terraform configuration, initialize a configuration directory, and plan and apply a configuration to create infrastructure.
Destroy the AWS EC2 instance you created in the previous tutorials. Evaluate the plan and confirm the destruction.
Store Remote State
Configure Terraform to store state in Terraform Cloud remote backend. Add a remote state block directly to configuration or set an environment variable to load remote state configuration when Terraform initializes.
- Terraform Cloud
Log in to Terraform Cloud from the CLI
Log into Terraform Cloud or Enterprise with the Terraform CLI to migrate state, trigger remote runs, and interact with Terraform Cloud from the command line.
- Terraform Cloud
Migrate State to Terraform Cloud
Keep your state secure and share it with collaborators by migrating it to Terraform Cloud. Initialize the Terraform Cloud backend and migrate the state file for existing infrastructure without destroying or modifying the infrastructure.
Customize Terraform Configuration with Variables
Customize infrastructure for a web application with Terraform. In this tutorial, you will use Terraform input variables, including lists, maps, strings, and booleans, to make the configuration for your infrastructure more flexible.
Output Data from Terraform
Output data about infrastructure with Terraform outputs. Provision a web application with Terraform, and use output values to export data about your application's infrastructure. Hide sensitive output values.
Query Data Sources
Use a data source to configure an EC2 instance with an appropriate AMI for the current region. Use a remote state data source to share data between Terraform projects and to support multiple availability zones.
Create Resource Dependencies
Create an implicit dependency between an EC2 instance and its Elastic IP using variable interpolation. Create explicit dependencies on an S3 Bucket and SQS Queue with depends_on. Learn how Terraform creates independent resources in parallel.
Perform Dynamic Operations with Functions
Deploy a web app on an EC2 instance, with user data generated by the templatefile function and interpolation. Find an AMI for your region with the lookup function. Use the concat function to create lists.
Manage Resources in Terraform State
Create an EC2 instance and security group, and move a resource to another state file. Remove, replace, and re-import resources to manage state and reconcile drift in your infrastructure.
Import Terraform Configuration
Import existing infrastructure into Terraform. In this tutorial, you will use Terraform import to manage an existing Docker container and learn important considerations to keep in mind when importing infrastructure into Terraform.
Manage Resource Drift
Create an AWS instance and security group. Manually change the instance to create drift in your Terraform state file. Reconcile your state drift and import your resources while avoiding downtime.
Use Refresh-Only Mode to Sync Terraform State
Use refresh-only plans and applies to update Terraform state to match real-world infrastructure. Understand the implicit refresh behavior in Terraform plan and apply operations.
Interpret and fix a Terraform configuration with common configuration language errors and deploy an EC2 instance with security groups in AWS. Learn best practices for logging application errors and reporting bugs.
Read about how Terraform modules make configuration easier to organize, understand, reuse, and share. Learn about the directory structure of a module, and how to call them.
Use Modules from the Registry
Use modules from the public Terraform Registry to define an Amazon VPC containing two EC2 instances. Select module and root input and output variables, install the modules, and apply the configuration.
Host a Static Website with S3 and Cloudflare
Set up an S3-hosted static website with Cloudflare for DNS, SSL and CDN. Redirect HTTP traffic to HTTPS, and redirect certain paths with Cloudflare page rules. Alternatively, use ACM for SSL certificate management and Cloudfront for CDN.
Provision Infrastructure with Cloud-Init
Deploy preconfigured infrastructure with Terraform using the Cloud-Init tool.
Provision Infrastructure with Packer
Create an image with Packer, containing SSH keys, a new user, and a demo webapp, and deploy it with Terraform.
- Team & Governance
Install the Sentinel CLI
Install the Sentinel CLI, a binary that allows you to run Sentinel policies locally. Then test the install by running a policy in the Sentinel CLI against Terraform Cloud data.
Inject Secrets into Terraform Using the Vault Provider
Configure the AWS Secrets Engine in Vault through Terraform, then use the short-lived, Vault-generated, dynamic secrets to provision EC2 instances