> Go to Git-Bash & run the below commands:
terraform version
→ Check the installed version of Terraformcd Documents/
→ Change directory to Documentsmkdir terraform
→ Create a new directory named “terraform”cd terraform
→ Change directory to terraform
ls
→ List files in the “terraform” directorymkdir dir1
→ Create a new directory named dir1 inside “terraform” directoryls
→ List files in the “terraform” directorycd dir1
→ Change directory to dir1
ls
→ List files in the “dir1” directory
vi [file1.tf](<http://file1.tf>)
Open file1.tf in vi editor and add the following content
# This below Code will connect Terraform with AWS
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
ls -a
→ List all files, including hidden files
Output:
. .. [file1.tf](<http://file1.tf/>)
terraform init
→ Initialize the directory for Terraform usage
Output:
shellCopy code
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 5.0"...
- Installing hashicorp/aws v5.0.0...
Terraform has been successfully initialized!
ls
→ List files in the current directory
Output:
file1.tf
ls -a
→ List all files, including hidden files
Output:
. .. .terraform .terraform.lock.hcl file1.tf
cat .terraform.lock.hcl
→ Display the content of .terraform.lock.hcl
Output:
# This file is generated by Terraform and contains the dependency lock for the project.
provider "registry.terraform.io/hashicorp/aws" {
version = "5.0.0"
...
}
ls -a
→ List all files, including hidden files
Output:
. .. .terraform .terraform.lock.hcl file1.tf
cd .terraform
→ Change directory to .terraform
ls
→ List files in the current directory
Output:
providers
cd providers/
→ Change directory to providers
ls
→ List files in the current directory
Output:
registry.terraform.io
cd ../../..
→ Change back to the original directory
ls
→ List files in the current directory
Output:
file1.tf
ls -a
→ List all files, including hidden files
Output:
. .. .terraform .terraform.lock.hcl file1.tf
cd dir1
→ Change directory to dir1 (already there)
ls
→ List files in the current directory
Output:
file1.tf
ls -a
→ List all files, including hidden files
Output:
. .. .terraform .terraform.lock.hcl file1.tf
Now connect your AWS cloud account with Terraform remotely by the following steps:
Go to your AWS Dashboard → Search for “IAM” → click on “Users” on the Right Dashboard → click on “Add users” → Name it as “terraformuser” → tick on “Programmatic access” → click on “Next Permissions” → select the “Attach existing policies directly” option → select the “AdministratorAccess” → click on “Next” → click on “Next” → click on “Create user” → Finally you can See or Download the ‘Access Key’ & ‘Secret Key’
> Go back to Git-Bash Terminal
vi [file1.tf](<http://file1.tf>)
→ Open file1.tf in vi editor and add the following content