![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*AytdNx89EfHTh7x_Czn3ow.png?w=1120&ssl=1)
In this walkthrough, we’ll be creating an S3 bucket in Amazon Web Services (AWS) using Terraform. This is a pretty straightforward walkthrough but you will change a bit of information in your .tf
files.
Prerequisites
AWS account
Terraform CLI
IDE (Pycharm or Cloud9 for example)
Step 1
Create a new IAM user with full S3 access. I’m going to grant my IAM user Administrator Access and S3 Full access.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*IxfIVUXGP9bojhtN3Aobvg.png?w=1120&ssl=1)
Using the aws configure
command, input your new IAM user’s credentials.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*VfUxHS5vQNUAz9cJZec8eA.png?w=1120&ssl=1)
Step 2
Head over to Github and fork this repository. Once you’ve done that, git clone
the repo in your CLI.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*vg88TnPzfIRgMMi4Yg5Keg.png?w=1120&ssl=1)
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*Ut8Y2xkZZD_zZacZ3qysEg.png?w=1120&ssl=1)
cd
into your repository.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*KcxgLiFY5fxb-QoHRLYFbg.png?w=1120&ssl=1)
Head over to your variables.tf
file as we are going to make a few updates.
The first thing you’ll want to do is change the region of your AWS account. In this case, my account is in us-east-1
. Next, you’re going to change the name of your S3 bucket making sure it is globally unique.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*KuDHqwhpax3uPYjmtafO2Q.png?w=1120&ssl=1)
There isn’t anything we have to change in the main.tf
file but let’s review a few main pieces of the code inside the file and what it’s going to do.
aws_s3_bucket_acl
: This part defines whether the bucket access will be private or not. In the AWS console, this is what it looks like.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*FCc4cV0YkMwQxh1Gom0u1A.png?w=1120&ssl=1)
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*5g7aSznlNasBBB8dLcY0-Q.png?w=1120&ssl=1)
aws_s3_bucket_public_access_block
: This line of code defines if the contents of the bucket can be publicly accessed or not. Setting this to “true” will block public access.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*Dn9cIdsX9KXJN5e8GmhuIw.png?w=1120&ssl=1)
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*P5-0AD7JW6US2CrT9qO1Mg.png?w=1120&ssl=1)
Step 3
Now that we’ve set up our configuration code, let’s initialize terraform with terraform init
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*snXY-OX_8TMPsctVlS9Rlg.png?w=1120&ssl=1)
Let’s run our code with terraform apply
and watch our S3 bucket be deployed.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*kOgrKBdXRZrfF564SsoCkA.png?w=1120&ssl=1)
To confirm that your S3 bucket has been created, head over to the AWS management console.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*LGc1FIbhTDF85L4PkUKUlw.png?w=1120&ssl=1)
Don’t forget to terraform destroy
your resources so you don’t incur any additional AWS charges outside of the free tier.
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*rE2UCE-dsAjEbqI02dVBLw.png?w=1120&ssl=1)
![](https://i0.wp.com/miro.medium.com/v2/resize:fit:1050/1*4tF0Qgsq76EYCz9KVdMbPA.png?w=1120&ssl=1)