The vpc_igw.tf File
| Filename | Location | Group | Project/Repository |
vpc_igw.tf | ./vpc_igw.tf | infrastructure | terraform |
Why?
Because we're keeping things simple, we're going to be using an Internet Gateway for Internet connectivity in and out of the VPC. This means our ALB, discussed later, will be able to talk to the Internet. It also means we'll be able to SSH into the web servers to provision them.
Breakdown
| resource "aws_internet_gateway" "httpcats" {
vpc_id = aws_vpc.httpcats.id
tags = merge(local.common_tags, {
"Name" = "httpcats"
})
}
|
A key component of this code is the vpc_id. We're setting this to the ID of the VPC we created in the vpc.tf file. This attaches the Internet Gateway to the VPC.
The Solution
| resource "aws_internet_gateway" "httpcats" {
vpc_id = aws_vpc.httpcats.id
tags = merge(local.common_tags, {
"Name" = "httpcats"
})
}
|
Committing the Code
- Set your working directory to the
infrastructure/terraform repository - Save the file as
vpc_igw.tf and use git add vpc_igw.tf to add it to the Git staging area - Use
git commit -am 'creating an internet gateway for our vpc' to commit the file to our repository - Push the code to GitLab.com:
git push