Table of Contents
#Introduction
How to create AWS VPC using Terraform. In this tutorial, I’m using Terraform AWS create VPC example.
Terraform aws create vpc example
The structure folder and files for AWS VPC are as follows
E:\STUDY\TERRAFORM\AWS
└───EC2
│ main.tf
│ outputs.tf
│ variables.tf
Terraform init command is used to initialize a working directory containing Terraform configuration files
terraform init
The output as the picture below

Use terraform plan command creates an execution plan.
terraform plan
The output as the picture below

Use terraform apply is to run it.
terraform apply
The output is the picture below

The result on AWS VPC

The content files for Terraform AWS VPC
main.tf file
# dry-run
# terraform plan
# Apply it
# terraform apply
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.region}"
}
# describe the VPC resource.
resource "aws_vpc" "myVPC" {
cidr_block = "10.1.0.0/16"
instance_tenancy = "default"
enable_dns_support = "true"
enable_dns_hostnames = "false"
tags = {
Name = "myVPC"
}
}
variables.tf file
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "region" {
default = "us-west-2"
}
outputs.tf file
output "test" {
value ="${aws_vpc.myVPC.cidr_block}"
}
Conclusion
You have to use Terraform AWS to create VPC. I hope will this your helpful. Thank you for reading the DevopsRoles page!