Using terraform to create infrastrucutre on AWS using code. In this code, we are trying to create a below items:
- VPC
- Public Subnet inside VPC
- Internet Gateway associated with VPC
- Route Table to Internet Gateway
- Security Group inside VPC
- Key Pair used for SSH access
- EC2 Instance inside our public subnet with an associated security group and generated a key pair
EC2 Operation System: Red Hat Enterprise Linux 8
openssl genrsa -out kp_devops.pem 1024
ssh-keygen -y -f kp_devops.pem > kp_devops.pub
- Initialize a Terraform working directory
terraform init
- Generate and show an execution plan
terraform plan -var-file=variables.tfvars
- Builds or change Infrastructure
terraform apply -var-file=variables.tfvars
- To destroy the Infrastructure
terraform destroy -var-file=variables.tfvars
Note: You can update/add variables in variables.tfvars file.
ssh -i kp_devops.pem ec2-user@<ipaddress>