Terraform and OpenTofu
Keep Terraform or OpenTofu state in XNS storage, and create buckets and objects on your Relayer with the AWS provider.
Overview
Terraform and OpenTofu work with XNS in two ways. The S3 backend stores the state file in a bucket on your Relayer and locks it with a lock file next to it. The AWS provider manages buckets and objects on the Relayer as resources. Both need the Relayer’s endpoint, path-style addressing and a set of skip_* flags that stop them calling AWS account services the Relayer does not have.
Tested with Terraform 1.16.6 and OpenTofu 1.13.1, with the hashicorp/aws provider 6.69.1, on 2026-10-18 against Relayer build 59a37e64.
Each run, over HTTP on port 9000 and over HTTPS on port 9443, ran init, plan and apply (a bucket with versioning and an uploaded object), checked the state file in the bucket and the object’s SHA-256, confirmed a second plan showed no changes, confirmed that a second run was refused while the state was locked, and ran destroy.
Connect to XNS
Every S3 tool connects to your Relayer with the same settings. Enter them exactly as shown; the notes below the table cover the two that most tools get wrong by default.
| Setting | Value |
|---|---|
| Endpoint (HTTP) | http://<relayer-host>:9000, where <relayer-host> is the address of the machine running your Relayer. Always available. |
| Endpoint (HTTPS) | https://<relayer-host>:9443, available only after a certificate is installed on the Relayer. Port 9000 never serves HTTPS. |
| Region | us-east-1 |
| Addressing | Path-style. In tools that ask, turn on force path style or path-style access, and turn off virtual-hosted style. |
| Signature | Signature Version 4 (V4). Version 2 is refused. |
| Access key and secret key | For a tool, create a scoped key: IAM → Create IAM User in the Relayer UI. The secret is shown once, so copy it then. The install’s root pair is on Configure → Credentials; keep it for administration. |
| Bucket | Create it first: Files → Create Bucket in the Relayer UI, or let the tool create it. Names are 3-63 characters of lowercase letters, digits, hyphens and periods. |
HTTPS and certificates. The Relayer UI offers two certificates for port 9443: Let’s Encrypt, which needs a domain managed in Cloudflare and a Cloudflare API token, or self-signed. Most tools refuse a self-signed certificate unless certificate verification is turned off in the tool. On a private network, plain HTTP on port 9000 avoids the question.
Path-style. A tool left on virtual-hosted style (often labeled Amazon S3 or AWS) sends the bucket name in the hostname, and the Relayer cannot find the bucket. Choose the tool’s S3 compatible or generic S3 option and set path-style.
Not supported: server-side encryption with customer-provided keys (SSE-C) or KMS keys (SSE-KMS), bucket website hosting and bucket replication. Server-side encryption with AES256 is accepted. See Encryption at the Gateway, Identity and Access and Configure.
Prerequisites
- Terraform 1.11 or later, or OpenTofu 1.10 or later, for
use_lockfile(Terraform downloads, OpenTofu install). The tested versions are listed above. - A bucket for the state, created in the Relayer UI. The backend does not create it.
- A key, stored in a profile and selected with
export AWS_PROFILE=xns(or theAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYvariables):- For the backend only, a key with the ReadWrite policy is enough.
- For the AWS provider to manage buckets, use a key with the FullAccess policy. Reading a bucket back calls
GetBucketAcl,GetBucketCorsand other bucket settings that ReadWrite does not grant.
Step 1: Configure the S3 backend
terraform {
backend "s3" {
bucket = "<state bucket>"
key = "prod/terraform.tfstate"
region = "us-east-1"
endpoints = { s3 = "http://<relayer-host>:9000" }
use_path_style = true
use_lockfile = true
skip_credentials_validation = true
skip_region_validation = true
skip_requesting_account_id = true
skip_metadata_api_check = true
skip_s3_checksum = true
}
}For HTTPS, set the endpoint to https://<relayer-host>:9443. The same block works unchanged in OpenTofu.
use_path_stylekeeps the bucket name in the path.skip_credentials_validation,skip_requesting_account_idandskip_metadata_api_checkstop calls to AWS STS, IAM and the EC2 metadata service.skip_region_validationallows the custom endpoint’s region.use_lockfilelocks the state with a.tflockobject in the same bucket, with no DynamoDB table.skip_s3_checksumis optional: runs without it also passed.
Step 2: Configure the AWS provider
provider "aws" {
region = "us-east-1"
s3_use_path_style = true
skip_credentials_validation = true
skip_region_validation = true
skip_requesting_account_id = true
skip_metadata_api_check = true
endpoints {
s3 = "http://<relayer-host>:9000"
}
}
resource "aws_s3_bucket" "data" {
bucket = "<new bucket>"
}
resource "aws_s3_bucket_versioning" "data" {
bucket = aws_s3_bucket.data.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_object" "file" {
bucket = aws_s3_bucket.data.id
key = "files/data.bin"
source = "${path.module}/data.bin"
etag = filemd5("${path.module}/data.bin")
lifecycle {
ignore_changes = [object_lock_legal_hold_status]
}
}The ignore_changes line is needed: the Relayer reports a legal hold status of OFF on every object, and without the line each plan proposes to change it.
Step 3: Run it
export AWS_PROFILE=xns
terraform init
terraform plan -out=tfplan
terraform apply tfplan
terraform plan -detailed-exitcode # exit code 0: no changes
terraform destroyWith OpenTofu, run the same commands with tofu. While one run holds the lock, a second run stops with Error acquiring the state lock (the Relayer answers 412 PreconditionFailed to the second lock write), and the lock file is removed when the first run ends.
Known limits
- The AWS provider needs a FullAccess key to manage buckets. With a ReadWrite key, creating a bucket fails on
GetBucketAclwith403 AccessDenied. - Add
ignore_changes = [object_lock_legal_hold_status]toaws_s3_objectresources, or every plan shows a change. - The state bucket must exist before
init. Turning on versioning for it in the Relayer UI keeps earlier state versions. - Only S3 resources apply. The Relayer is an S3 endpoint; IAM, KMS and other AWS services in the provider have nothing to talk to.
- Not supported by the Relayer: SSE-KMS state encryption (
kms_key_id), SSE-C (sse_customer_key), bucket website hosting and bucket replication resources.encrypt = true(AES256) was not tested.
