Skip to content

Object storage

This creates a bucket with a size ceiling and an access key an application can use. The S3 service must be switched on for the organization first. Open Object Storage in the panel and choose Enable Object Storage, or see Enable the S3 service.

terraform {
  required_providers {
    virtscale = {
      source  = "registry.terraform.io/virtscale/virtscale"
      version = "~> 0.2"
    }
  }
}

# No credentials here: VIRTSCALE_API_KEY and VIRTSCALE_ORGANIZATION come from the environment.
provider "virtscale" {}

resource "virtscale_s3_bucket" "logs" {
  name           = "example-logs"
  versioning     = true
  max_size_bytes = 107374182400 # 100 GiB
  max_objects    = 1000000
}

resource "virtscale_s3_access_key" "app" {}

output "s3_access_key_id" {
  value = virtscale_s3_access_key.app.access_key_id
}

# The secret is in the state, marked sensitive: keep the state in an encrypted backend.
output "s3_secret_access_key" {
  value     = virtscale_s3_access_key.app.secret_access_key
  sensitive = true
}

tofu apply waits until the bucket is active, up to 20 minutes.

The bucket name is 3 to 63 lowercase letters, digits and hyphens, starting and ending with a letter or digit, with no dots and no two hyphens in a row. Names such as admin and api, and prefixes such as vs- and s3-, are kept by the platform. The name is checked at plan time, and is unique within the organization. max_size_bytes and max_objects are optional; leave them out for no per-bucket cap. They change in place. versioning is fixed when the bucket is created: changing it is refused at plan time.

The secret is hidden in plan and apply output, and tofu output hides it too. Print it on purpose, into the environment of the tool that needs it:

export AWS_ACCESS_KEY_ID="$(tofu output -raw s3_access_key_id)"
export AWS_SECRET_ACCESS_KEY="$(tofu output -raw s3_secret_access_key)"
aws s3 ls s3://example-logs --endpoint-url https://s3.virtscale.nl --region default

The Connect tab under Object Storage in the panel shows the endpoint, region and addressing style the API publishes. They are https://s3.virtscale.nl, region default and path-style addressing unless it says otherwise. The same list is in List published S3 endpoints.

The API returns the secret exactly once, in the answer to the request that creates the key. The provider keeps it in the state, marked sensitive, and nowhere else. So the state holds a credential:

  • Keep the state in an encrypted backend, or use OpenTofu’s state encryption (OpenTofu 1.7 or newer).
  • Do not print the secret in an output without sensitive = true.
  • A saved plan (tofu plan -out), tofu output -json and tofu show -json print sensitive values in clear text. Keep them as safe as the state.
  • A key’s secret cannot be read back. An imported key has none: its secret_access_key is null.

The key belongs to the organization’s storage, not to one bucket. It reaches every bucket, and it can delete buckets and objects directly over S3, bypassing the soft delete below. An organization holds at most 5 keys.

To rotate, replace the resource. The old key is revoked and a new one is created:

tofu apply -replace=virtscale_s3_access_key.app

Destroying the resource revokes the key.

Destroying a bucket is a soft delete. The API marks it deleting_soft and answers at once. Its data is kept for 7 days, and Restore a bucket brings it back in that time. A worker cuts access to the bucket. In tests that took about 8 seconds, so a bucket you just destroyed can stay reachable over S3 for a few seconds. Its name stays taken until the data is erased, and a new bucket of that name gets 409 bucket_already_exists. The organization also holds a limited number of deleted buckets (422 bucket_retention_limit_reached), so do not create and destroy buckets in a loop.

A bucket that holds objects is refused with 409 bucket_not_empty, but only once the platform has metered it. The API judges from the platform’s last usage sample, not from a fresh look, and a sample is taken every 10 minutes. A bucket the platform has not metered yet (no usage sample so far) can be destroyed with objects in it even with force_destroy = false. It is soft-deleted like any other, so the objects can be restored for 7 days. On a versioned bucket the sample counts previous versions that a plain listing does not show. To destroy a bucket that holds objects on purpose, set force_destroy = true, run tofu apply so the setting is stored, then destroy again.

Import existing resources, or Troubleshooting.