- Download Terraform CLI
- Extract and move terraform inside
binfolder
mv ~/Downloads/terraform /usr/local/bin/
terraform version
- Create a new project and a file with extension
.tf - Copy and paste the below script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| provider "aws" { | |
| version = "~> 2.0" | |
| region = "us-west-2" | |
| shared_credentials_file = "~/.aws/credentials" | |
| profile = "prashanth" | |
| } | |
| data "aws_ami" "amazon-linux-2" { | |
| most_recent = true | |
| owners = ["amazon"] | |
| filter { | |
| name = "name" | |
| values = ["amzn2-ami-hvm*"] | |
| } | |
| filter { | |
| name = "architecture" | |
| values = ["x86_64"] | |
| } | |
| } | |
| resource "aws_instance" "test" { | |
| ami = "${data.aws_ami.amazon-linux-2.id}" | |
| associate_public_ip_address = true | |
| instance_type = "t2.micro" | |
| } |
- Now, initialize terraform
terraform init
- Compile the terraform file for any issues
terraform plan
- Finally apply terraform
terraform apply -auto-approve