Project: Create a VPC and Two Subnets

Try implementing a Terraform project.

Problem statement#

Write a Terraform module that creates a VPC and 2 subnets. The module takes inputs for the CIDR ranges for the VPC and subnets and should return the created VPC and each subnet as an output. Create a Terraform project that uses the module and print the output of the module to the console.

Inputs#

As defined in the problem statement, the module takes inputs for the CIDR ranges and for the VPC and subnets.

Output#

The module should return the created VPC and each subnet as an output.

After running the terraform apply command, the output on the terminal should look like this:

Project output after running the terraform apply command

Folder structure#

Let’s look into the folder structure of this project:

Terraform project files used to implement the project

Running the project#

Clicking the RUN button will run the following commands:

terraform init
terraform apply

Coding exercise#

Try to solve the above problem. If you can’t solve it, don’t give up. In the next lesson, we will discuss the solution in detail.

Good Luck!

This code requires the following environment variables to execute:
access_key_id
Not Specified...
secret_access_key
Not Specified...
/
vpc
main.tf
terraform.tfstate
terraform.tfstate.backup
Solution Review: Find the CIDR Range
Solution Review: Create a VPC and Two Subnets
Mark as Completed
Report an Issue