Terraform.
Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp, that lets you build, change, and version cloud and on-prem resources safely and efficiently in human-readable configuration files that you can version, reuse, and share.
Amazon S3.
Amazon Web Services (AWS) S3 (Simple Storage Service) is a scalable, high-performance cloud storage service that allows businesses and developers to store and retrieve data from anywhere on the web. It is probably the most commonly used, go-to storage service for AWS users given the features like extremely high availability, security, and simple connection to other AWS Services. Includes features like versioning, lifecycle management, and replication (cross-region or same-region replication). S3 is designed for 99.999999999% (11 9s) of durability, meaning your data is safe and highly available.
In this article, I will walk you through the process of launching an Amazon S3 bucket using a Terraform script, with Visual Studio Code (VSCode) as the code editor.
Prerequisite:
- AWS Account
- Terraform Installation
- AWS CLI
TASK1 : Create IAM user.
Step 1: Navigate the IAM and click on User .

STEP 2: Click on create user.

STEP 3: Enter the user name and click on next button.

STEP 4: Select attach policies directly.
- Tick on amazons3full access.
- Then, next click on next button.

STEP 5: Click on create user.

TASK 2: Create access key.
STEP 1: Click your user name and select on create access key.
- Select the command line interface and tick confirmation.
- Click on create access key.
- Download the csv.file.
- You will get Access key and secret key.




TASK 3: Configure Profile Using AWS Configure Command.
STEP 1: Configuration.
aws configure
configure list
- You will paste your Access key.
- Paste your Secret access key.
- Click on enter.


TASK 4: Create terraform file(.tf) & write the script.
STEP 1: Open your folder on your VScode.
- Create the provider.tf file.
- Enter the following script.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.82.2"
}
}
}
provider "aws" {
# Configuration options
region ="us-east-1"
}
STEP 2: Save the file.

STEP 3: Open the terminal and enter the terraform init.

STEP 4: Create the another main.tf file.
- Enter the following script and save the file.
# Bucket creation
resource "aws_s3_bucket" "my_s3_bucket"{
bucket = "mys3testbucket0"
tags = {
Name = "My bucket"
Enviroment ="Dev"
}
}

TASK 5: Execute the terraform script.
STEP 1: Go to terminal enter the terraform plan.

STEP 2: Then, next Enter the terraform apply.

TASK 6: Verify S3 bucket is create or not.
STEP 1: Go to S3 bucket and verify your bucket.

STEP 2: If you are delete your bucket you the terraform destroy command.

Conclusion.
In this tutorial, we’ve successfully demonstrated how to launch an Amazon S3 bucket using a Terraform script, with Visual Studio Code as our development environment. By following these steps, you can easily automate the creation and management of S3 buckets, saving time and reducing human error in your cloud infrastructure setup. Terraform’s declarative approach ensures that your configurations are repeatable and consistent, making it an ideal tool for scalable cloud management.
With this foundational knowledge, you can expand on this setup, integrating other AWS resources, and further optimizing your cloud environment using Terraform. Happy coding and deploying!
Add a Comment