How to create a simple AWS S3 Bucket using 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.
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 providers.tf 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 variables.tf file which we will see in a moment.
Next, I have configured the variables.tf 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.
Finally, the s3.tf file needed to create the s3 bucket. View code below.
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)
- 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.