How to create a simple AWS S3 Bucket using Terraform

Create s3 bucket in Terraform

What is needed for this very sweet and simple introduction to creating an AWS s3 Bucket in Terraform.

  • IDE of your choice.
  • AWS Admin user account.
  • Terraform installed

I will first create a root directory called, “Terraform” and will then add the following files as seen below in the tree.

Root directory called, “Terraform” and the files need to create the s3 bucket, and

The first file created is going to be the providers file which is necessary in order to install any plugins necessary for remote systems communications.

The file will also refer to the region I want to create my s3 bucket in as seen below. Referencing the variable region which is located in the file which we will see in a moment.

above the file w/ a variable referencing the region which is defined in the file

Next, I have configured the file referencing the region which is the one I am currently logged into “us-east-1” and the unique name of my s3 bucket (“bude25adfff1”) as no two buckets can have the same name. You can view the code below. file which is referencing my current region for the bucket creation and bucket name identified by default = “bude25adfff1”

Finally, the file needed to create the s3 bucket. View code below. file could be called anything I choose as well as all of the file names I have chosen. You just want to make sure you are using something your readers will be able to follow and understand.

After the creation of the code. I ran the following commands to sure things up.

  • Terraform init
  • Terraform fmt
  • Terraform validate
  • Terraform plan
  • Terraform apply (type yes when you get the prompt when running this command)
s3 bucket creation “bude25adfff1”
  • Terraform Destroy (after confirming infrastructure has been built above)

As, mentioned at the beginning of my article; this is a sweet and simple introduction to creating an s3 bucket. Follow me in my next article as I will be building the s3 bucket using Terraform Modules. Where I will be adding things such as static website hosting and the s3 bucket will be created as private and made accessible on AWS’s Content Delivery Network using CloudFront.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Eric Wainwright

Eric Wainwright

DevOps engineer in search of Cloud Engineer role. Looking for Cloud Operations or Cloud Infrastructure opportunities.