Navrangpura, Ahmedabad, Gujarat
Follow us :

To use Terraform to construct an Amazon S3 bucket, you must define an appropriate resource block in your Terraform setup. Here’s a step-by-step tutorial on creating an S3 bucket with Terraform:

1 Configure AWS Credentials:
Before you continue, make sure you have your AWS credentials set up. You can use the AWS CLI aws configure command or specify them as environment variables.

2 Follow these steps to create a Terraform configuration:
Create a.tf file (for example, main.tf) to define your Terraform setup.

3 Define the S3 Bucket:
Add the following Terraform code to your main.tf file to define an S3 bucket resource:

terraform {
  required_providers {
    aws = {
        source = "hashicorp/aws"
        version = "5.8.0"
    }
  }
}

provider "aws" {
  region     = "ap-south-1"
  access_key = "Your_Access_Key"
  secret_key = "Your_Secrt_Key"

}

resource "aws_s3_bucket" "bucket" {
  bucket = "highskybucket"

  tags = {
    Name        = "My bucket"
  }
}

Replace “highskybucket” with your S3 bucket’s unique name. Bucket names must be globally distinct throughout AWS.

4 Launch Terraform:
To launch Terraform, browse to the directory containing your Terraform configuration file and execute the following command:

 terraform init

5 Plan the Configuration:
In HashiCorp Terraform, the terraform plan command generates an execution plan outlining the modifications Terraform will make to your infrastructure based on your existing configuration. Without actually making the changes, it demonstrates to you what steps Terraform will take to create, update, or remove resources, for example. By doing so, you may examine and confirm the modifications before implementing them in your infrastructure.

terraform plan

6 Apply the Configuration:
Run the following command to create the AWS s3 Bucket:

terraform apply

7 Review and Confirm:
Terraform will display a plan of what it aims to build. After reviewing the plan, type yes to confirm and create the AWS s3 Bucket.

Output On AWS Infra

And Go To s3 Service 

How To Create IAM User and assign policy to user by Terraform

How to create ec2 instance using terraform

Author

by admin

bg

Subscribe to our Newslatter

Sign Up to Our Newsletter to Get Latest Updates & Services

mail box
logo-footer
HighSky IT Solutions Pvt. Ltd. is a leading IT training and certification programs in Red hat, RSCSA Cloud, Open-source, AWS, Devops and various domains.
Contact Info

2nd floor, Rohera Arcade, opp SOTC office, Near Navrangpura police station, Navrangpura, Ahmedabad -380009 Gujarat

Copyright ©2024 Design & Developed by HighSky IT