Skip to content

The vpc.tf File

Filename Location Group Project/Repository
vpc.tf ./vpc.tf infrastructure terraform

Why?

The Virtual Private Cloud (VPC) gives us our own private Cloud within AWS' networks. This is the first networking element we need to get the networking ball rolling.

Breakdown

1
2
3
4
5
6
7
resource "aws_vpc" "httpcats" {
  cidr_block = "10.1.1.0/24"

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

We're going for a /24 sized network here because that offers us enough IPs to do what we need. We could just use a /16, but it's good practice to keep your networks as small as you can. You never know when you'll need all 65,000 IPs... ;-)

The Solution

1
2
3
4
5
6
7
resource "aws_vpc" "httpcats" {
  cidr_block = "10.1.1.0/24"

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

Terraform Documentation

| Type | Documentation | | - | - | - | | aws_vpc | Terraform AWS Provider |

Committing the Code

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

Last update: August 25, 2021