This repo contains the sample code for the blog post series A Comprehensive Guide to Terraform. The examples correspond to the following parts of the series:
- An Introduction to Terraform
- single-web-server: Deploy a single EC2 Instance with a web server that will return "Hello, World" for every request on port 8080.
- cluster-of-web-servers: Deploy a cluster of EC2 Instances in an Auto Scaling Group (ASG) and an Elastic Load Balancer (ELB). The ELB listens on port 80 and distributes load across the EC2 Instances, each of which runs the same "Hello, World" web server.
- How to Manage Terraform State
- s3-backend: Create an S3 bucket and DymamoDB table to use as a Terraform backend.
- database: Deploy MySQL on top of Amazon's Relational Database Service (RDS).
- How to create reusable infrastructure with Terraform modules
- Terraform tips & tricks: loops, if-statements, and pitfalls
- loops-with-count: Examples of how to use the
count
parameters to "loop" over resources. - loops-with-for-each: Examples of how to use
for_each
to "loop" over inline blocks. - loops-with-for: Examples of how to use
for
to "loop" over individual values.
- loops-with-count: Examples of how to use the
Note: These examples deploy resources into your AWS account. Although all the resources should fall under the AWS Free Tier, it is not our responsibility if you are charged money for this.
- Install Terraform.
- Set your AWS credentials as the environment variables
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
. cd
into one of the example folders.- Run
terraform init
. - Run
terraform apply
. - After it's done deploying, the example will output URLs or IPs you can try out.
- To clean up and delete all resources after you're done, run
terraform destroy
.
Please see LICENSE.txt for details on how the code in this repo is licensed.