The module creates an object storage bucket in DigitalOcean Spaces. Spaces Object Storage is an Amazon S3-compatible object storage service.

Allows configuring essential parameters:

  • toggle versioning
  • toggle access mode
  • attach externally defined JSON policies

NOTE: DigitalOcean has issues when creating policies for Spaces, similar to issues in older versions of S3 policies, with which Spaces is compatible. If there are multiple policies, the module automatically combines them into one.
See this issue in AWS Terraform provider

NOTE: DigitalOcean Spaces is compatible with Amazon S3. As a result, there is a limit of 20 KB to the length of a single policy.
See this Amazon S3 documentation article

Storage Bucket in DigitalOcean

Storage Bucket management in DigitalOcean
$250
BUY
610
Log in to Corewide IaC registry

Once you have a Corewide Solutions Portal account, this one-time action will use your browser session to retrieve credentials:

 shellterraform login solutions.corewide.com
Provision instructions

Initialize mandatory providers:

Copy and paste into your Terraform configuration and insert the variables:

 hclmodule "tf_do_spaces_bucket" {
  source  = "solutions.corewide.com/digitalocean/tf-do-spaces-bucket/digitalocean"
  version = "~> 1.0.0"

  # specify module inputs here or try one of the examples below
  ...
}

Initialize the setup:

 shellterraform init
Define update strategy

Corewide DevOps team strictly follows Semantic Versioning Specification to provide our clients with products that have predictable upgrades between versions. We recommend pinning patch versions of our modules using pessimistic constraint operator (~>) to prevent breaking changes during upgrades.

To get new features during the upgrades (without breaking compatibility), use ~> 1.0 and run terraform init -upgrade

For the safest setup, use strict pinning with version = "1.0.0"

v1.0.0 released 8 months, 2 weeks ago

Setup with custom configuration, versioning enabled, access_mode is private and a policy assigned:

 hclmodule "spaces" {
  source  = "solutions.corewide.com/digitalocean/tf-do-spaces-bucket/digitalocean"
  version = "~> 1.0"

  name        = "foo"
  region      = "fra1"
  access_mode = "private"
  versioning  = true

  bucket_policies = {
    policy-deny-delete-objects = jsonencode({
      Version = "2012-10-17"
      Statement = [
        {
          Effect    = "Deny"
          Principal = "*"

          Action = [
            "s3:DeleteObject",
          ]

          Resource = [
            "arn:aws:s3:::${module.spaces.bucket.name}/protected/*",
          ]
        }
      ]
    })

    policy-allow-read-write-bucket = jsonencode({
      Version = "2012-10-17"
      Statement = [
        {
          Effect    = "Allow"
          Principal = "*"

          Action = [
            "s3:GetObject",
            "s3:PutObject",
            "s3:DeleteBucket",
            "s3:ListBucket",
          ]

          Resource = [
            "arn:aws:s3:::${module.spaces.bucket.name}",
            "arn:aws:s3:::${module.spaces.bucket.name}/*",
          ]
        }
      ]
    })
  }
}

Minimal setup with default parameters:

 hclmodule "spaces" {
  source  = "solutions.corewide.com/digitalocean/tf-do-spaces-bucket/digitalocean"
  version = "~> 1.0"

  name   = "foo"
  region = "fra1"
}

Simple configuration with publicly accessible storage:

 hclmodule "spaces" {
  source  = "solutions.corewide.com/digitalocean/tf-do-spaces-bucket/digitalocean"
  version = "~> 1.0"

  name        = "foo"
  region      = "fra1"
  access_mode = "public-read"
}
Variable Description Type Default Required Sensitive
name Spaces bucket name. Maximum length is 63 characters (56 characters when add_random_suffix is enabled) string yes no
region DigitalOcean region to create resources in string yes no
access_mode Spaces bucket access mode. Allowed values: private, public-read string private no no
add_random_suffix Append a random suffix to the bucket name to ensure uniqueness. Please note: modifying this variable will trigger the re-creation of the bucket bool false no no
bucket_policies JSON-formatted policies to attach to the bucket. Each policy should be a single JSON object in string format map(string) {} no no
versioning Enable versioning for the bucket bool true no no
Output Description Type Sensitive
bucket Contains all the Spaces Bucket attributes resource no
Dependency Version Kind
terraform >= 1.1 CLI
digitalocean/digitalocean ~> 2.18 provider
hashicorp/random ~> 3.6 provider

Not sure where to start?
Let's find your perfect match.