Bootstrap FreeKB - Amazon Web Services (AWS) - Create S3 Bucket using Terraform
Amazon Web Services (AWS) - Create S3 Bucket using Terraform


An S3 Bucket is similar to an NFS share in that it is a mountable storage volume.

This assumes you have setup Terraform with the Amazon Web Services (AWS) provider. If not, check out my article Amazon Web Services (AWS) Getting Started with Terraform.

Let's say you have the following files on your Terraform server.

├── required_providers.tf
├── s3_buckets (directory)
│   ├── provider.tf
│   ├── buckets.tf

 

required_providers.tf will almost always have this.

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

 

Let's say provider.tf in the network_load_balancer directory has the following. In this example, the "default" profile in /home/username/.aws/config and /home/username/.aws/credentials is being used. This assumes you have setup Terraform as described in Amazon Web Services (AWS) - Getting Started with Terraform.

provider "aws" {
  alias   = "default"
  profile = "default"
  region  = "default"
}

 

And let's say buckets.tf contains something like this.

resource "aws_s3_bucket" "my_bucket_fjfnv9d3d9" {
  bucket = "my-bucket-fjfnv9d3d9"

  tags = {
    Name        = "my-bucket-fjfnv9d3d9"
    Environment = "staging"
  }
}

 

You may need to run the terraform init command.

terraform init

 

The terraform plan command can be used to see what Terraform will try to do.

terraform plan

 

And the terraform apply command can be used to create the S3 Bucket.

terraform apply

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter ebed19 in the box below so that we can be sure you are a human.