A Terraform provider for managing policy.opteryx access policies as code, instead of through ad-hoc API calls.
opteryx_access_policy(resource) — a single principal/role/pattern grant, backed bypolicy.opteryx's/v1/access/workspace/{workspace}/policies...CRUD endpoints.opteryx_access_policies(data source) — lists every policy in a workspace, backed by the list endpoint. Useful for auditing existing grants or finding a policy'sidto import.
Not published anywhere — used locally via Terraform's dev_overrides (see Usage below). No public registry publishing is planned; that would need a HashiCorp registry account but not any other involvement from HashiCorp.
- Go matching the
godirective ingo.mod(currently 1.25+) - Terraform 1.0+ (for local testing with the CLI)
make build # go build -o terraform-provider-opteryx
make install # builds, then go install's it onto $GOPATH/binNo Go installed locally? Push a branch or open a PR — .github/workflows/build.yml runs go mod tidy, gofmt, go vet, go build, and go test on every push and pull request against main.
This isn't published to any registry, so Terraform can't find it via a normal terraform init. Point Terraform at your locally built binary instead, using dev_overrides:
-
Build and install it:
make install # go build, then go install — lands in $(go env GOPATH)/bin -
Add a dev override to
~/.terraformrc(create the file if it doesn't exist):provider_installation { dev_overrides { "mabel-dev/opteryx" = "/Users/you/go/bin" # $(go env GOPATH)/bin } direct {} }
-
Write config that uses it — see
examples/for a startingprovider.tfandopteryx_access_policyresources. Withdev_overridesactive you skipterraform initfor this provider entirely (Terraform prints a warning that overrides are in effect and skips its lock-file check). -
Get a token.
tokenmust be a bearer JWT for an owner/admin identity that is not a principal in any policy this config manages.authenticate.opteryx's access tokens are short-lived — 5 minutes (ACCESS_TOKEN_EXPIRATION_MINUTESin itsapp/core.py) — so exporting one by hand will likely expire mid-apply. Mint one immediately before each run instead, e.g. with a client-credentials identity (seeauthenticate.opteryx'sPOST /clients/{client_id}/credentialsto create one,POST /tokento exchange it):./examples/run-terraform.sh plan ./examples/run-terraform.sh apply
That wrapper fetches a fresh
OPTERYX_TOKENfromOPTERYX_CLIENT_ID/OPTERYX_CLIENT_SECRETand execsterraform "$@".
provider "opteryx" {
endpoint = "https://policy.opteryx.app" # optional, or OPTERYX_ENDPOINT
token = var.opteryx_token # required, or OPTERYX_TOKEN
}token is a bearer JWT minted by authenticate.opteryx (the same kind clients present to any opteryx service). Two things to know before pointing this at a real workspace:
- Self-grant/self-modify is rejected at the API, not just in the UI.
policy.opteryxrefuses to let an identity create, update, or delete a policy where it is the principal (app/routes/v1/access.py, thecreate_policy/update_policy/delete_policyhandlers). If the identity behind your token ever appears as aprincipalin the same config,applywill fail with a 403 from the service, not a Terraform-side validation error. Use a distinct owner/admin identity to run Terraform. roleis validated here but not everywhere downstream.authenticate.opteryxmints whatever string is stored into the JWT'spoliciesclaim without checking it against theowner/admin/writer/readerenum (see the fleet's Opteryx services map notes) —policy.opteryx's own validation, which this provider's schema mirrors viastringvalidator.OneOf, is the only thing stopping a bad role from reaching production tokens. Don't bypass it by hand-editing state.
resource "opteryx_access_policy" "analytics_reader" {
workspace = "analytics"
principal = "jane@example.com"
role = "reader"
pattern = "analytics.sales.*"
}| Attribute | Type | Notes |
|---|---|---|
workspace |
string | Required. Forces replacement — the API has no move/rename. |
principal |
string | Required. Forces replacement — PUT has no way to reassign a policy's principal. "*" means any authenticated user. |
role |
string | Required. One of owner, admin, writer, reader. Updatable in place. |
pattern |
string | Required. Updatable in place. A wildcard principal ("*") must pair with an exact, non-glob pattern. |
id |
string | Computed. The Firestore document ID policy.opteryx assigns. |
created_at |
string | Computed. |
updated_at |
string | Computed. |
updated_by |
string | Computed. |
Reserved patterns (public.*, personal.*, *.information_schema.*) are rejected by the API regardless of what the provider sends — see app/models/policy.py::validate_pattern_does_not_target_reserved_resource in policy.opteryx.
terraform import opteryx_access_policy.analytics_reader analytics/3f2b1a9e-1234-4c56-9abc-0123456789abThe import ID is workspace/policy_id — a policy ID alone doesn't say which workspace's Firestore subcollection to look in.
data "opteryx_access_policies" "analytics" {
workspace = "analytics"
}
output "analytics_grants" {
value = data.opteryx_access_policies.analytics.policies
}Returns policies, a list of { id, principal, role, pattern } objects — one per policy document in the workspace. Useful for auditing what's granted today, or for finding a policy's id to hand to terraform import.
make test # unit tests -- currently just compile-time checks, no unit tests yet
make testacc # acceptance tests -- hits a REAL policy.opteryx instance, creates/destroys real policiestestacc requires:
| Env var | Purpose |
|---|---|
OPTERYX_TOKEN |
Bearer token for an owner/admin identity |
OPTERYX_TEST_WORKSPACE |
A workspace that identity governs |
OPTERYX_TEST_PRINCIPAL |
A different identity to grant policies to during the test — the token's own identity can't be a principal |
main.go # plugin entrypoint
internal/client/ # hand-written HTTP client for the access-policy API
internal/provider/ # provider + resource implementations (terraform-plugin-framework)
examples/ # example .tf used to generate registry docs later
tfplugindocs generatefordocs/once the schema stabilizes- Release automation (GoReleaser + GitHub Actions) if/when this needs to reach the public registry — not required for private/local use (
dev_overridesor a private registry work without HashiCorp's involvement)