Create S3 bucket for TYPO3 with Terraform

In this post we will create a simple AWS S3 bucket and an administrative user which can be used to connect your TYPO3 instance with the S3 bucket.

Since cloud services become bigger and extremely powerful it’s highly recommended to manage your cloud infrastructure as code instead of clicking around in the web interfaces.
We will use Terraform to setup our AWS infrastructure.

I published a blueprint to create your S3 bucket for TYPO3 with Terraform:
https://github.com/different-technology/typo3-s3-bucket-example

Setup Terraform & AWS

If you are already able to run terraform commands with your AWS account you can skip this step. If not, please follow the next steps.

Install the AWS CLI and follow the documentation to setup your configuration and credential files.
You can define multiple profiles in these files, so let’s call our profile [private-aws-account] instead of [default].

To use your profile you can set an environment variable

export AWS_PROFILE=private-aws-account

Create Terraform project

Now let’s create a Terraform project for our TYPO3 instance and include the blueprint as module.

Create a new repository or open your TYPO3 project and create a subdirectory e.g. infrastructure. Create file main.tf:

module "my_cool_bucket_and_admin" {
  source = "git::git@github.com:different-technology/typo3-s3-bucket-example.git"
  region = "eu-central-1"
  environments = ["staging", "prod"]
  namespace = "my-application"
  s3_bucket_name = "my-typo3-s3-bucket"
}

Now initialize the Terraform project:

terraform init

Create S3 bucket & admin

Once everything is done let’s do a dry run first.

terraform plan

You will receive an output of what will be created by Terraform.
If it looks fine to you we will create the resources for you in real.

terraform apply

Please confirm the changes with typing “yes” to the console.

Create AWS Access Key

The Terraform script will create the admin user with all required permissions for us. But it will not create the access key and the secret. This is because Terraform would save the secret in the state file. This should be avoided to protect your secrets.
Creating the access key is easy:

  1. Login to the AWS Console
  2. Navigate to “IAM” → “Users” or click here
  3. Select the just created users (one for each environment)
  4. Open tab “Security Credentials” and click on “Create access key”
  5. Copy the “Secret access key” – you will never see it again

Configure TYPO3 driver

Install the extension I described in this blog post:
Connect TYPO3 with AWS S3

Open the TYPO3 backend and enter all details to your new file storage.

TYPO3 storage configuration

Next step: CDN

To enable your own domain, use HTTPS and to increase the performance of your S3 files around the world you should setup a CDN. AWS provides us CloudFront as CDN.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.