Terraform Block: The terraform {} block is required so Terraform knows which provider to download from the Terraform Registry. In the configuration above, the AWS provider’s source is defined as hashicorp/AWS which is shorthand for registry.terraform.io/hashicorp/aws.

Providers:  The provider block configures the named provider, in our case AWS, which is responsible for creating and managing resources.

Resources: The resource block defines a piece of infrastructure. A resource might be a physical component such as an EC2 instance, or it can be a logical resource such as a Heroku application.

Get access_key and secret_key from aws dashboard.

Terraform File:

provider “aws” {

  region          = “us-east-1”

  access_key =           

  secret_key  = 

  token           = 


resource “aws_instance” “web” {

  ami                  = “ami-0be2609ba883822ec”

  instance_type = “t2.micro”


Use the terraform init command to initialize the provider.

Check the changes using the terraform plan command.

Terraform plan 

To apply those changes use the terraform apply command.

terraform apply

Check the EC2 dashboard to see our newly created instance.