Skip to content

Latest commit

 

History

History

06-Terraform-VPC-Demo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Terraform VPC Demo

TO-DO : execute the terraform commands to create VPC using vpc.tf and update the command documentation with screenshots

Step 01 : Create a file 00_provider.tf file to include terraform and provider block

terraform {
  required_providers {
    aws = {
    source = "hashicorp/aws"
    version = "~> 5.0"
    }
  }
}

provider "aws" {
    region = "us-east-1"

    default_tags {
      tags = {
        terraform = "yes"
        project = "terraform-learning"
      }
    }
}

00_provider.tf

Step 02: Create a file 01_vpc.tf to create resource block to create AWS VPC

01_vpc.tf

Step 03: Authenticate to AWS via IAM Credentials

  • Terraform AWS Authentication Types

    • Static Credentials - You can use this under provider section, but its NOT A RECOMMENDED Option
    • Environment variables - Recommended Option (example below)
    • IAM credentials stored locally (configuration file $HOME/.aws/credentials)
      • use aws configure to configure the aws credentials
  • Example : Using Environment variables via PowerShell

    • AWS Authentication via Environment variables

Step 04: Execute Terraform Commands

Initialize Terraform

terraform init

Validate Terraform Configuration files

terraform validate

Execute Terraform Plan

terraform plan

Deploy AWS Resources

terraform apply
or
terraform apply -auto-approve (if you want to avoid the prompt) NOT Recommended for beginners

Step-05: Clean-Up

Destroy Terraform Resources

terraform destroy
or
terraform destroy -auto-approve (if you want to avoid the prompt) NOT Recommended for beginners

Delete Terraform Files from current directory

Linux

rm -rf .terraform*
rm -rf terraform.tfstate*

Windows:

Delete the lock file .terraform* and state file terraform.tfstate files from the folder

References