to create a secured 3 tier infrastructure in aws Step-01: Introduction Understand basic Terraform Commands terraform init terraform validate terraform plan terraform apply terraform destroy Step-02: Review terraform manifest for EC2 Instance Pre-Conditions-1: Ensure you have default-vpc in that respective region Pre-Conditions-2: Ensure AMI you are provisioning exists in that region if not update AMI ID Pre-Conditions-3: Verify your AWS Credentials in $HOME/.aws/credentials
terraform { required_providers { aws = { source = "hashicorp/aws" #version = "~> 3.21" # Optional but recommended in production } } }
provider "aws" { profile = "default" # AWS Credentials Profile configured on your local desktop terminal $HOME/.aws/credentials region = "us-east-1" }
resource "aws_instance" "ec2demo" { ami = "ami-04d29b6f966df1537" # Amazon Linux in us-east-1, update as per your region instance_type = "t2.micro" } Step-03: Terraform Core Commands
terraform init
terraform validate
terraform plan
terraform apply Step-04: Verify the EC2 Instance in AWS Management Console Go to AWS Management Console -> Services -> EC2 Verify newly created EC2 instance Step-05: Destroy Infrastructure
terraform destroy
rm -rf .terraform* rm -rf terraform.tfstate* Step-08: Conclusion Re-iterate what we have learned in this section Learned about Important Terraform Commands terraform init terraform validate terraform plan terraform apply terraform destroy