Skip to content

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

1
2
3
4
5
6
7
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

1
2
3
4
5
6
7
resource "aws_internet_gateway" "httpcats" {
  vpc_id = aws_vpc.httpcats.id

  tags = merge(local.common_tags, {
    "Name" = "httpcats"
  })
}

Terraform Documentation

Type Documentation
aws_internet_gateway Terraform AWS Provider

Committing the Code

  1. Set your working directory to the infrastructure/terraform repository
  2. Save the file as vpc_igw.tf and use git add vpc_igw.tf to add it to the Git staging area
  3. Use git commit -am 'creating an internet gateway for our vpc' to commit the file to our repository
  4. Push the code to GitLab.com: git push

Last update: August 25, 2021