Terraform provider reference / guides / object-storage

Object storage (S3)

An object storage project is a project of its own, with a token of its own. The provider manages what the platform owns - buckets, S3 access keys, service accounts limited to one bucket, and the storage reservation the project is billed for. What lives inside a bucket - objects, lifecycle rules, CORS, the bucket policy, versioning - is S3 territory: manage it with the aws provider (or any S3 tool) pointed at the storage endpoint.

1. A second provider configuration

A token belongs to ONE project of ONE product. A Virtual Data Center token does not reach the object storage, and an object storage token does not reach servers: the platform answers not_found, and the provider says that the token belongs to another product.

The FIBERAX_TOKEN environment variable is shared by every provider configuration, so the second configuration needs its token written in its token field (from a variable, not as a literal in a file you commit):

provider "fiberax" {
  # the VDC project: token from FIBERAX_TOKEN
}

provider "fiberax" {
  alias = "storage"
  token = var.storage_token
}

variable "storage_token" {
  type      = string
  sensitive = true
}

Every object storage resource and data source then carries provider = fiberax.storage.

2. Buckets, keys and service accounts

resource "fiberax_object_storage_bucket" "backups" {
  provider = fiberax.storage
  name     = "acme-backups"
}

resource "fiberax_object_storage_access_key" "ci" {
  provider = fiberax.storage
  lifecycle {
    create_before_destroy = true
  }
}

resource "fiberax_object_storage_service_account" "app" {
  provider = fiberax.storage
  name     = "app-writer"
  bucket   = fiberax_object_storage_bucket.backups.name
  access   = "readwrite"
}

3. Secrets live in state

The platform returns a secret only once - in the answer that created the key or the service account. The provider keeps it in the sensitive attribute secret_access_key, which is hidden in plan output, but the state file holds it in the clear: keep the state where secrets may be kept.

After terraform import there is no secret. For an S3 access key the API action POST /v1/object-storage/access-keys/{access_key_id}/actions/reveal-secret shows it again (the provider has no actions); a service account has no such action, and the way to a secret is replacing it.

If the answer to a create is lost (a dropped connection, a platform error), the provider checks what appeared anyway:

4. The reservation is money

resource "fiberax_object_storage_reservation" "this" {
  provider    = fiberax.storage
  reserved_tb = 2
}

The project is billed every hour for every reserved terabyte (1 TB = 2^40 bytes), whatever is stored. Raising reserved_tb orders storage at once, and the reservation never goes down: not here, not in the client area. The only way down is deleting the whole storage with its data in the client area. The plan says how much the reservation grows - read it before you approve.

The bounds and step of an order are in reservation_limits of the fiberax_object_storage data source.

5. Objects with the aws provider

Keep the objects in a second configuration, not next to the key. The aws provider is configured before anything is applied, so a key created in the same configuration is still unknown at that moment: the first plan fails with "No valid credential sources found", and while such a block is present terraform import of a fiberax resource fails with "depends on values that cannot be determined until apply".

The storage configuration (sections 1-4) hands the key over as outputs:

output "s3_access_key_id" {
  value = fiberax_object_storage_access_key.ci.access_key_id
}

output "s3_secret_access_key" {
  value     = fiberax_object_storage_access_key.ci.secret_access_key
  sensitive = true
}

The objects configuration takes the endpoint and region from the data source - it is read during the plan, so the values are known - and the key from the environment:

data "fiberax_object_storage" "this" {
  provider = fiberax.storage
}

provider "aws" {
  region                      = data.fiberax_object_storage.this.region
  s3_use_path_style           = true
  skip_credentials_validation = true
  skip_region_validation      = true
  skip_requesting_account_id  = true

  endpoints {
    s3 = data.fiberax_object_storage.this.endpoint
  }
}

resource "aws_s3_object" "readme" {
  bucket  = "acme-backups"
  key     = "README.txt"
  content = "kept by Terraform"
}
export AWS_ACCESS_KEY_ID="$(terraform -chdir=storage output -raw s3_access_key_id)"
export AWS_SECRET_ACCESS_KEY="$(terraform -chdir=storage output -raw s3_secret_access_key)"
export AWS_REQUEST_CHECKSUM_CALCULATION=when_required
export AWS_RESPONSE_CHECKSUM_VALIDATION=when_required
terraform -chdir=objects apply

6. Pace

The platform takes one change of an object storage at a time, and the provider sends them one by one by itself. A plan with dozens of service accounts also meets the write limit of a token (20 writes a minute): the provider waits and repeats on its own, so such a run takes minutes rather than seconds.

Generated from the provider schema for version 0.11.0. How to install the provider: Terraform provider.