Files
seaweedfs/terraform/provider
Chris LuandClaude Opus 5.5 79e99e7865 terraform: add a SeaweedFS Terraform provider for S3, IAM and S3 Tables (#13478)
* terraform/provider: import the SeaweedFS Terraform provider

Import terraform-provider-seaweedfs by Luís Costa (MIT) as a nested Go
module. It manages S3 buckets and their configuration (tags, CORS,
lifecycle, versioning, policy, encryption, public access block,
ownership controls, request payment, quota), IAM users, access keys,
groups, roles, policies, attachments, OIDC providers and service
accounts, and S3 Tables buckets, namespaces, tables, policies and
maintenance configuration.

The module path and the provider source address move to seaweedfs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: build and test in-tree

Drop the standalone repo's release and git-hook instructions, credit the
original author, and list the provider in the terraform layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform: vet and unit-test the provider in CI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: keep configured JSON in state after apply

Bucket, group, managed and S3 Tables policies stored the compacted JSON
sent to the server, so a policy written as a heredoc or with file()
failed apply with an inconsistent result. Keep the planned string, and
keep configured table metadata while the server's copy is semantically
equal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: read IAM policy documents without query unescaping

SeaweedFS returns user, group and managed policy documents as raw JSON
and role trust policies path-escaped. Query unescaping turned a "+" in a
resource into a space and failed on a literal "%". Return valid JSON as
is and path-unescape anything else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: keep service account settings left out of the config

description, expiration and status are optional and computed, so a
change to another attribute planned them as unknown and Update sent
empty values. SeaweedFS reads an empty Expiration as "never expires".
Carry the prior state forward for unknown values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: use the root IAM path in the full example

The user resource accepts only "/", so the example failed at user
creation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: make the smoke test and local build portable

Use the in-repo chart by default and check it before touching the
cluster, bind the port-forward to 127.0.0.1 and fail when it does not
start, build from the module directory, and point dev_overrides at the
directory holding the binary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: keep large JSON numbers exact when normalizing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: compare single statements, empty Sid and scalar conditions canonically

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: reject unknown provider settings instead of using the environment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: do not adopt a bucket owned by another identity

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: clear tags of an adopted bucket when the config sets none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: report bucket configuration settings SeaweedFS did not store

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: treat empty and absent lists alike when comparing bucket configuration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: refuse to adopt an existing IAM user unless a retried create made it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: keep omitted role settings so a trust policy change updates in place

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: resend a service account expiration only when it changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: keep a configured expiration that names the same instant

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: stop retrying CreateAccessKey when a failed attempt left a key

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: add new group members before removing old ones

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: reject empty or padded OIDC client IDs, thumbprints and URL

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: keep an empty OIDC list as a known empty set

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: reject an empty namespace or name for a table policy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: compare table metadata with the server's omitted required=false

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: do not replace a table when only metadata formatting differs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: keep a created S3 Tables object in state when its cleanup fails

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: reject an explicitly empty compaction strategy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: document import IDs and the object lock versioning destroy case

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: stop on any uncertain CreateAccessKey failure and name the keys it left

Only NoSuchEntity (user not visible yet) is retried. Any other failure,
including cancellation and a failure on the last attempt, lists the
user's keys once more and reports the new ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: do not adopt an IAM user found after a failed CreateUser attempt

A retry that hits EntityAlreadyExists cannot tell whether the failed
attempt or another client created the user, so ask for an import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: point BucketAlreadyExists on bucket create to terraform import

SeaweedFS answers BucketAlreadyExists both for another identity's bucket
and for the caller's own bucket that has an ACL, so the create cannot
adopt it safely.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: treat omitted public access block flags as false when comparing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: restore the BucketOwner-only note on the request payment resource

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: say the smoke test runs the version the chart deploys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* terraform/provider: make the unknown endpoint test check the unknown-setting error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 22:08:19 -08:00
..

terraform-provider-seaweedfs

Terraform and OpenTofu provider for SeaweedFS S3, IAM, and S3 Tables APIs. The provider targets SeaweedFS 4.51 API behavior and supports importing every managed resource; each resource's documentation lists its import identifier.

Originally written by Luís Costa as terraform-provider-seaweedfs and licensed under the MIT license in LICENSE.

Managed resources

  • S3 buckets: bucket lifecycle and tags, CORS, lifecycle rules, versioning, bucket policies, encryption, public access block, ownership controls, requester-pays configuration, and SeaweedFS bucket quotas.
  • IAM: users, access keys, inline user/group policies, groups and authoritative group membership, roles and trust policies, managed policies, user/group/role policy attachments, OIDC providers, and service accounts.
  • S3 Tables: table buckets and policies, namespaces, Iceberg tables and table policies, resource tags, and bucket/table maintenance configuration.

S3 bucket configuration documents and S3 Tables table metadata are passed as JSON strings using the SeaweedFS/AWS API field names. IAM and S3 Tables policy documents are JSON strings as well.

Lifecycle and secret notes

  • Destroying bucket versioning suspends versioning; S3 has no operation to remove the versioning configuration. Request-payment destroy resets the payer to the bucket owner, and quota destroy disables the quota.
  • S3 Tables maintenance configuration has no delete API; destroy disables the maintenance type.
  • A service-account secret is returned only at creation and is retained in Terraform state. sensitive masks CLI output but does not encrypt state. Use an encrypted, access-controlled state backend and protect state backups.
  • SeaweedFS stores one active managed-policy version; policy updates replace that document in place.

Object data operations, cluster installation, and irreversible object-lock configuration are intentionally not modeled as Terraform resources.

SeaweedFS compatibility

IAM feature availability can vary between SeaweedFS deployments. In particular, CreateAccessKey has returned ServiceFailure: Internal server error in some deployments. Run the integration smoke test against the exact SeaweedFS version and configuration you intend to use before relying on IAM resources.

Build

cd terraform/provider
go build -o bin/terraform-provider-seaweedfs .

Generate Docs

make docs

This runs tfplugindocs via go generate and updates files under docs/.

Use locally with Terraform

Create ~/.terraformrc:

provider_installation {
  dev_overrides {
    "seaweedfs/seaweedfs" = "/absolute/path/to/seaweedfs/terraform/provider/bin"
  }
  direct {}
}

Then in your Terraform config:

terraform {
  required_providers {
    seaweedfs = {
      source = "seaweedfs/seaweedfs"
    }
  }
}

provider "seaweedfs" {
  endpoint   = "https://s3.example.com"
  region     = "us-east-1"
  access_key = var.admin_access_key
  secret_key = var.admin_secret_key
}

resource "seaweedfs_iam_user" "example" {
  name = "example-user"
}

endpoint, access_key, and secret_key may alternatively be supplied by SEAWEEDFS_ENDPOINT, SEAWEEDFS_ACCESS_KEY, and SEAWEEDFS_SECRET_KEY. SEAWEEDFS_REGION defaults to us-east-1; SEAWEEDFS_INSECURE accepts true/false and defaults to false. Explicit provider configuration takes precedence over environment variables.

Tests

make test-race
make lint

The terraform: validate and test modules workflow builds, vets and unit-tests this module on every change under terraform/.

Local SeaweedFS integration smoke test

The smoke fixture exercises bucket/tagging, core IAM, S3 Tables, and table maintenance create/read behavior with OpenTofu against the SeaweedFS version the chart deploys (by default the in-tree k8s/charts/seaweedfs, whose appVersion sets the image tag; set SEAWEEDFS_CHART to use another chart):

make test-race
tofu fmt -check -recursive
./scripts/minikube-smoke.sh

The script requires a running Minikube profile, seaweedfs-podman-smoke by default (set MINIKUBE_PROFILE to use another). It installs the chart from k8s/charts/seaweedfs unless SEAWEEDFS_CHART points elsewhere, and forwards the S3 port to 127.0.0.1:${SEAWEEDFS_LOCAL_PORT:-8333}. It creates the namespace and Helm resources if needed, but does not delete the cluster, release, or Terraform resources. It applies the example automatically; use only a disposable test cluster and review the local example state before any manual cleanup.