Creating a Bucket via MinIO Terraform Provider

Last change on 2024-12-03 • Created on 2024-09-23 • ID: ST-507F6

To create a Bucket via Terraform, this example will use the aminueza/minio Terraform Provider.

  1. Install Terraform

    Before you start, make sure Terraform is installed and you have S3 credentials:

  2. Setup your files

    Create a new directory for your project and add the files minio.tf and terraform.tfvars.

    You should end up with a directory tree that looks like this:

    terraform/
    ├── minio.tf
    └── terraform.tfvars
  3. Setup the Terraform configuration

    Edit minio.tf with a text editor of your choice and add the following content:

    Replace fsn1 with your preferred location.

    terraform {
      required_providers {
        minio = {
          source = "aminueza/minio"
        }
      }
    }
    
    variable "access_key" {}
    variable "secret_key" {}
    
    provider "minio" {
      minio_server   = "fsn1.your-objectstorage.com"
      minio_user     = "${var.access_key}"
      minio_password = "${var.secret_key}"
      minio_region   = "fsn1"
      minio_ssl      = true
    }
    
    resource "random_uuid" "id" {}
    
    resource "minio_s3_bucket" "bucket" {
      bucket         = random_uuid.id.result
      acl            = "private"
      object_locking = false
    }

    This will create a new Bucket with a random name (random_uuid) and a visibility setting of private.

    To enable object locking, change the value of object_locking from "false" to "true".

    You can find the complete documentation about the MinIO Terraform provider in the Terraform documentation.

  4. Setup your variables

    Edit terraform.tfvars with a text editor of your choice and add the following content:

    Replace YOUR_ACCESS_KEY and YOUR_SECRET_KEY with your actual keys.

    access_key = "YOUR_ACCESS_KEY"
    secret_key = "YOUR_SECRET_KEY"
  5. Create the Bucket

    Make sure you're in the same directory as the files you just created and run the following command to create a new Bucket:

    terraform init
    terraform apply

In Cloud Console, you should now also see the new Bucket. To remove the Bucket you just created, you can run terraform destroy in the same directory in which you just ran terraform apply.


Next: