Writing our Infrastructure¶
Now we're going to look at the structure of our code. We'll look at the directory structure I (highly) recommend you stick to, as well as a naming convention that will help you manage your code in the long run.
You're free to go outside of this advice, especially if it helps you learn, but just remember that if I refer to a particular file further on in this book, or in the community during a community session, you might struggle to follow along.
Directory Structure¶
The structure of our Terraform code is very simple, and very flat:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
We're going to create these files as we go along through the sections of this chapter.
Meta Data¶
Let's look at each part of the structure in a bit of detail, file by file, and determine a few details:
- The filename I (highly) recommend you use
- The AWS technology being used, or
- Whether the file is specific to Terraform
- And the tier it belongs to in the stack
This information is to help you understand where each file fits into the architecture we saw previously.
File | Service | Tier |
---|---|---|
main.tf | Terraform | Meta |
locals.tf | Terraform | Meta |
inputs.tf | Terraform | Meta |
key_pairs.tf | EC2 Key Pairs | Security |
vpc.tf | Virtual Private Cloud | Networking |
vpc_igw.tf | Internet Gateway | Networking |
vpc_subnets.tf | VPC Subnets | Networking |
security_groups.tf | AWS Security Groups | Security |
ec2.tf | EC2 Instances | Compute |
ec2_eip.tf | Elastic IPs | Networking |
alb.tf | Application Load Balancer | Networking |
route53.tf | AWS Route53 | Networking |
acm.tf | Amazon Certificate Manager | Security |
Next¶
Now let's start exploring each of these files, one by one, and writing them out, from top to bottom.