Program 1 - Download the AWS provider

Content of first.tf

provider "aws" {
} 

Command:-

$ terraform init

Program 2 - Provide the AWS API access to Terraform

Content of first.tf

provider "aws" {
  access_key = "AKIAIAR3RTLAJ34Z5GVQ"
  secret_key = "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"
  region     = "ap-south-1"
}

Program 3 - Create a EC2 Instance

Content of first.tf

provider "aws" {
  access_key = "AKIAIAR3RTLAJ34Z5GVQ"
  secret_key = "RQbCk7CZM73tMjDOOqKUKw4no05VjQTy3hKmsroE"
  region     = "ap-south-1"
}

resource "aws_instance" "example" {
  ami           = "ami-5b673c34"
  instance_type = "t2.micro"
}

Command:-

$ terraform plan
$ terraform apply

Program 4 - Create a EC2 Instance & Add a Tag

Content of first.tf

provider "aws" {
  access_key = "AKIAIAR3RTLAJ34Z5GVQ"
  secret_key = "RQbCk7CZM73tMjDOOqKUKw4no05VjQTy3hKmsroE"
  region     = "ap-south-1"

resource "aws_instance" "example" {
  ami           = "ami-5b673c34"
  instance_type = "t2.micro"

  tags {
    Name = "HelloWorld"
  }
}
}

Command:-

$ terraform plan
$ terraform apply