Untitled

I. Installing Terraform

Via HomeBrew

Installation commands

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

To uninstall terrafrom via homebrew

brew uninstall terraform
terraform --version
#if uninstalled, "command not found" messsage.

Via ARM64 or AMD64

uname -m
#Download the file arm64 or amd64 or use the below command.
curl -LO <https://releases.hashicorp.com/terraform/1.12.1/terraform_1.12.1_darwin_arm64.zip>
(curl -LO <https://releases.hashicorp.com/terraform/><version>/terraform_<version>_<OS>_<arch>.zip)
cd Downloads && ls
unzip terraform_1.12.1_darwin_arm64.zip 
sudo mv terraform/usr/local/bin/
Enter password
terrafrom --version
Terraform [version] on darwin arm64

========
-L = Follow redirects
Tells curl to follow HTTP redirects (which HashiCorp's download URLs often use).
-O = Output to a file with the same name
 without -O You’d need to manually specify the filename:
Saves the downloaded file using the original filename from the URL — in this case, terraform_1.8.3_darwin_arm64.zip.
for a custome file name
-o expects a filename immediately after it

image.png

To uninstall terraform for AMD64 or ARM64

sudo rm /usr/local/bin/terraform
#OR the below command to remove entire directory
sudo rm -f /usr/local/bin/terraform
terraform --version

II. Creating a directory and .tf files.

#either in desktop or downlods make a directory 
ls
cd Downloads or Desktop
mkdir "Foldername"
touch provider.tf && touch main.tf

image.png

III. Creating S3 Buckets with Terraform

# In **provider.tf** file enter the following code
#Configure the aws provider
terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "5.95.0"
    }
  }
}

provider "aws"{
region ="ap-northeast-1" #or one closest to you
access_key ="YOUR_ACCESS_KEY"
secret_key ="YOUR_SECRET_KEY"
}

image.png

Best practice : Don’t hardcode credentials directly into the code, instead use the export command.

export ACCESS_KEY = "your-access-key"
export SECRET_KEY = "your-secret-key"
#then run the following commands in the terminal
terrafrom init
terraform plan
terraform apply