Week 9 assignment
Assignment
In this assignment, you will automagically create various AWS resources (Infrastructure as Code) using Terraform.
You will likely need to refer to the terraform AWS documentation to figure out how to do some of it. Here is the link.
Order doesn’t matter in the terraform file so the ordering of my steps below is irrelevant. I created everything in a single tf file.
YOU SHOULD APPROPRIATELY TAG EACH RESOURCE (YOU DECIDE HOW)
Tasks
- Create a new vpc
tf-vpc
- cidr block should be 10.0.0.0/16
- Create a new subnet
tf-subnet
- cidr block is 10.0.1.0/24
- Create a new security group
tf-sg
- should allow all incoming traffic to ports 80 and 22
- should allow all outgoing traffic
- Create an internet gateway
tf-ig
and attach it to your vpc. (Hint: vpc_id = aws_vpc.tf-vpc.id ) - Create a route table
tf-r
and attach to your vpc.- the cidr block should be
0.0.0.0/0
- the gateway id should point to the aforementioned
tf-ig
- the cidr block should be
- You need to create a
aws_route_table_association
to associate your route table with your subnet. The documentation will help. - Create an
aws_key_pair
namedtf-key
. You will have to give it a public key. If you are doing this on the ssh machine, you should already have a public key in~/.ssh/id_rsa.pub
, use that for the public_key argument for this resource. If you do not already have a public key on the machine you are running terraform from, you can generate one by doingssh-keygen
. - Create 3 separate ec2 instances
dev
,test
, andprod
. I used separate resource definitions for each.- Each should use an appropriate ubuntu AMI
- t2.micro
- associate the aforementioned
tf-sg
with each instance - associate_public_ip_address should be set to true
key_name
should be set to your previously created keytf-key
.- associate the instance with the subnet you created.
- The user data for each instance should consist of this file.
- You should have a line that outputs the public ip address of each machine (so 3 in total)
- When you run
terraform apply
successfully, you should be able to ssh to each of your virtual machines with something likessh ubuntu@54.165.61.116
. You should also be able to visit port 80 of each machine in a browser to see if a webpage is showing.
To pass off
Pass off in class or via office hours. Or I guess you could record a video of things working and cat out your tfstate file.
Last Updated 02/07/2025