Create First AWS Resource

let's create a directory with name aws-first-instance

mkdir aws-first-instance

let's create a file with the name provider.tf (you can change the name of the file as per your requirement.) with the below content.

provider "aws" {
  region     = "us-east-1"
  access_key = "YOUR_ACCESS_KEY_HERE"
  secret_key = "YOUR_SECRET_KEY_HERE"
}

put your access key and secret key that you get from aws.

now we are going to create an instance on AWS so let's create one more file in the same directory named as instance.tf with the below content

resource "aws_instance" "web" {
  ami                    = "ami-0b0ea68c435eb488d"
  instance_type          = "t2.micro"
  tags = {
    Name = "first-tf-instance"
  }
}

now let's run terraform init command.

┌──(gaurav㉿learning-ocean)-[~/terraform/youtube-course/aws-first-instance]
└─$ terraform init
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using previously-installed hashicorp/aws v3.71.0
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

now lets run terraform apply

┌──(gaurav㉿learning-ocean)-[~/terraform/youtube-course/aws-first-instance]
└─$ terraform apply

Demo Video