cd ~/environment/terraform/modules/tf-vpc
## Initialize Terraform
terraform init
## Format code, validate syntax & check security issues
terraform fmt
terraform validate
## Terraform "plan" what it is going to do
terraform plan -out tfplan
## Build the VPC
terraform apply tfplan
## Destroy what we have created !!!
# terraform destroy -auto-approve
⭐ Terraform is used in several stages, you have already completed the initialize stage.
`
✅ How to write VPC Networking using Terraform Infrastructure as Code
terraform {
required_version = "~> 0.14.10"
required_providers {
aws = {
source = "hashicorp/aws"
## Allow any 3.36+ version of the AWS provider
version = "~> 3.36"
}
}
}
provider "aws" {
region = "ap-southeast-1"
shared_credentials_file = "~/.aws/credentials"
profile = "default"
}
resource "aws_vpc" "tf-vpc" {
assign_generated_ipv6_cidr_block = false
cidr_block = "172.30.0.0/24"
enable_dns_hostnames = true
enable_dns_support = true
instance_tenancy = "default"
tags = {
"Name" = "CI/CD-VPC"
}
}
resource "aws_vpc" "tf-vpc" {
assign_generated_ipv6_cidr_block = false
cidr_block = "172.30.0.0/24"
enable_dns_hostnames = false
enable_dns_support = true
instance_tenancy = "default"
tags = {
"Name" = "CI/CD-VPC"
}
}
terraform plan -out tfplan
## Terraform State
ls terraform.tfstate
## List the contents of the Local State
terraform state list
terraform state show aws_vpc.tf-vpc