Ticket Type: Task
Title: Terraform Variables with AWS VPC
Project: Cloud Infrastructure Deployment
Assignee: You
Reporter: Derek Morgan
Priority: High
Labels: Terraform, AWS, Variables, VPC
Epic Link: AWS Infrastructure Expansion
Sprint: Sprint 01/Variables
Lab Setup
This lab uses Localstack to simulate an AWS environment. Localstack is already preinstalled in your environment. You don't need keys or to configure the provider. If you'd like to use your own account, feel free to specify your provider configuration and run unset aws and unset terraform to decouple them from Localstack.
Description:
Your team needs to set up a new Virtual Private Cloud (VPC) in AWS to host your application infrastructure. The VPC needs to be configured in such a way that all its attributes are modular and their values are stored in a variables.tf file. Read the acceptance criteria below to accomplish this task.
Acceptance Criteria:
Note: If the
terraform validatecommand fails, all tasks in the lab will fail!
- In
main.tf, create an AWS VPC resource with Terraform. - For the VPC name tag, use "project" and "env" variables to construct a name separated by a hyphen. E.g.
infrastructure-dev - For the VPC description tag, use the same variables to create a description similar to this:
infrastructure dev vpc. - Create a variable for the
enable_dns_hostnamessetting, but ensure it asks for the value when you run a Terraform operation. - Create a variable for the
cidr_blocksetting and default it to10.0.0.0/16. - The variables in the variables.tf file should all have a type and description. Make sure to include appropriate default values where needed.
resource "aws_vpc" "this" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "infrastructure-dev"
Description = "infrastructure dev vpc"
}
}
7. Apply the configuration and take note of how you can automatically provide the value for enable_dns_hostnames and pass the value into an apply without having to define it manually.
Implementation Notes: