Virtual Network Creation Using Terraform

Creating a virtual network with Terraform

Now that you’ve gone through the main components of Terraform, how to get up and running, and the concepts of what each Terraform configuration is, let’s take that knowledge and put it to action by creating a Terraform module!

Project overview

In this chapter project you will create a virtual network (vNet) using the following Terraform concepts:

  • A main.tf configuration file

  • A variables.tf configuration file

  • A terraform.tfvars variable definition file

Once the configuration is created, you will then initialize, validate, and finally deploy the Azure vNet.

Note: All Terraform configuration files need to be in a single directory.

Building the variable configuration file

Although it’s tempting to begin building the main configuration file first, it’s usually best to create the variable configuration file (if you have one) first. You’ll typically want to build this file first to know how the environment will be defined.

  1. In VS Code, create a new file and save it as variables.tf.

  2. Open the variables.tf configuration file and copy/paste the below content.

Get hands-on with 1400+ tech skills courses.