Table of Contents
Introduction
How to create AWS VPC using Terraform. In this tutorial, I’m using Terraform AWS create VPC example. Embark on a journey to mastering cloud infrastructure with our detailed tutorial on creating a Virtual Private Cloud (VPC) in AWS using Terraform.
This guide is tailored for DevOps professionals and enthusiasts eager to leverage the scalability and efficiency of AWS. By the end of this tutorial, you will have a clear understanding of how to set up a VPC that aligns perfectly with your organizational needs, ensuring a secure and robust network environment.
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 the terraform plan command to create 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
Congratulations on successfully creating your AWS VPC using Terraform! This guide aimed to simplify the complexities of cloud networking, providing you with a solid foundation to build upon. As you continue to explore Terraform and AWS, remember that the flexibility and power of these tools can significantly enhance your infrastructure’s reliability and performance.
Keep experimenting and refining your skills to stay ahead in the ever-evolving world of cloud computing. I hope will this your helpful. Thank you for reading the DevopsRoles page!