Project: Create a VPC with a CIDR Range

Test your knowledge by implementing a Terraform project that creates a VPC.

Problem statement#

Write a Terraform project that creates a VPC with a CIDR range set from a variable in a region set by another variable. Then apply the project and set the CIDR variable using a file and the region using an environment variable.

Input#

region = "eu-west-1"
cidr = "10.0.0.0/16"

Output#

aws_vpc.vpc: Creating...
aws_vpc.vpc: Creation complete after 6[id=vpc-03ec583d3a6812019]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Files structure#

We can use the following files to implement the project:

Terraform project files used to implement the project

variables.tf#

Use variables.tf file to define variables.

terraform.tfvars#

Use terraform.tfvars file to set cidr.

main.tf#

Implement your complete solution here.

Running the project#

You can use the following commands to run the project:

Terraform init and apply commands used to run the project

📝Note: Clicking the RUN button will run the terraform init command.

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...
/
main.tf
variables.tf
terraform.tfvars
🎉Quiz
Solution Review: Create a VPC with a CIDR Range
Mark as Completed
Report an Issue