DEV Community

Sreya Sharma
Sreya Sharma

Posted on

Day 03: Creating and Managing an AWS S3 Bucket Using Terraform

On Day 03 of my Terraform learning journey, I focused on creating and managing an AWS S3 bucket using Infrastructure as Code. This exercise helped reinforce how Terraform manages resource lifecycles and how even small configuration changes are reflected safely and predictably in the actual cloud infrastructure.
This blog documents the complete process—from bucket creation to modification and cleanup using Terraform commands.

**

Overview of the Use Case:

**

The goal was to:

  • Create an AWS S3 bucket using Terraform
  • Initialize and plan the infrastructure
  • Apply changes automatically
  • Verify the resource in the AWS Console
  • Modify the configuration and observe updates
  • Finally, destroy the infrastructure cleanly

Terraform Configuration for an S3 Bucket

The same Terraform structure used earlier was followed, with the addition of an S3 resource and tags.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }
}

# Configure the AWS Provider
provider "aws" {
  region = "us-east-1"
}

# Create S3 bucket
resource "aws_s3_bucket" "example" {
  bucket = "my-tf-sreya-04"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}
Enter fullscreen mode Exit fullscreen mode

**

Initializing and Planning the Infrastructure

**

After writing the configuration, the standard Terraform workflow was followed.

Terraform Initialization

terraform init
Enter fullscreen mode Exit fullscreen mode

This command ensured:

  • The AWS provider was downloaded
  • The working directory was initialized
  • Terraform was ready to manage resources
Terraform Plan
Enter fullscreen mode Exit fullscreen mode

The plan command displayed a preview of the actions Terraform would perform, confirming that the S3 bucket would be created along with the specified tags.

Applying the Configuration

To create the S3 bucket, the configuration was applied.

terraform apply
Enter fullscreen mode Exit fullscreen mode

At this stage, Terraform prompted for confirmation before proceeding. To skip this interactive approval step, the following command was used:

terraform apply --auto-approve
Enter fullscreen mode Exit fullscreen mode

This executed the plan automatically and created the S3 bucket.
Updating the Bucket Configuration

Next, a change was made to the configuration by modifying the tag value, specifically the bucket name under tags.

tags = {
Name = "My bucket 2.0"
Environment = "dev"
}

After saving the changes, the following commands were executed:

terraform plan
terraform apply --auto-approve
Enter fullscreen mode Exit fullscreen mode

Terraform detected the modification and updated the tag value without recreating the bucket. Refreshing the AWS Console confirmed that the updated tag name was reflected immediately.

**

Destroying the Infrastructure

**

To clean up and avoid unnecessary AWS usage, the S3 bucket was removed using Terraform.

terraform destroy
Enter fullscreen mode Exit fullscreen mode

Terraform displayed the resources that would be deleted. After confirmation, the S3 bucket was destroyed successfully.

Refreshing the AWS Console confirmed that the bucket no longer existed.

Key Learnings from Day 03:

  • Terraform manages the full lifecycle of cloud resources
  • Tags can be updated without recreating the resource
  • terraform init prepares the working directory
  • terraform plan previews infrastructure changes
  • **terraform apply --auto-approve enables non-interactive execution
  • terraform destroy cleanly removes managed resources

Top comments (0)