> ## Documentation Index
> Fetch the complete documentation index at: https://sariva.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# State backend & CI network

> Pre-create the Terraform state backend per stage and confirm CI egress.

> [!NOTE]
>
> Kubernetes/EKS only. On a VM, skip this page.

> [!NOTE]
>
> This page is now a detailed reference. For the copy-paste customer path that combines S3 state, DynamoDB locking, GitHub OIDC, IAM policy, and GitHub Actions secrets, use [AWS + GitHub Actions](https://sariva.mintlify.site/install-setup/access-and-state/aws-github-actions.md).

> [!NOTE]
>
> **Setup wizard → Step 6 (Terraform state backend).** The wizard recorded your backend *choice*; this page is where you create the actual S3 bucket + DynamoDB lock table — before the first `terraform apply`.

## Terraform state backend (per stage)

A **stage** is one **AWS account boundary** — for example `dev` and `prod` are two stages (you named them in the wizard's **Step 5**). Each stage gets its own state backend — an S3 bucket and a DynamoDB lock table — because Terraform state isolation matches the AWS account boundary.

> [!WARNING]
>
> Create the backend **before** merging the first agent-generated PR. The Sariva platform performs **zero** validation of state-backend access; the first `terraform plan` from your CI runner is the authoritative gate, so a wrong region or missing IAM grant surfaces as the exact AWS API error.

The wizard's step 6 asked which mode per stage:

* **`byob` (bring your own bucket) — default.** You create the bucket + lock table — or reuse ones you already have, just put their names in the wizard and skip the creation commands below. The wizard wrote the names into `values.yaml::tf_state`.
* **`agent_created`.** The Sariva platform opens a bootstrap PR per stage that creates the backend, then migrates to remote state in the same CI job:

  ```bash theme={null}
  sariva setup state-backend --stage nonprod
  sariva setup state-backend --stage prod
  ```

  This is separate from growth ops because backend creation needs admin-level AWS permissions the day-to-day CI runner role doesn't have.

**Manual `byob` creation (once per stage):**

```bash theme={null}
# Bucket (versioning + AES-256 + public-access-block)
aws s3api create-bucket --bucket acme-nonprod-tf-state --region us-east-1
aws s3api put-bucket-versioning --bucket acme-nonprod-tf-state \
  --versioning-configuration Status=Enabled
aws s3api put-bucket-encryption --bucket acme-nonprod-tf-state \
  --server-side-encryption-configuration \
  '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'
aws s3api put-public-access-block --bucket acme-nonprod-tf-state \
  --public-access-block-configuration \
  BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true

# DynamoDB lock table
aws dynamodb create-table --table-name acme-nonprod-tf-lock \
  --attribute-definitions AttributeName=LockID,AttributeType=S \
  --key-schema AttributeName=LockID,KeyType=HASH \
  --billing-mode PAY_PER_REQUEST --region us-east-1
```

Repeat for each stage from the wizard's step 6.

## CI runner network prerequisites

Your CI runner needs outbound HTTPS to these endpoints to run `terraform init` and `apply`:

| Endpoint | Why |
| - | - |
| `registry.terraform.io` | Provider downloads (`confluentinc/confluent`, `hashicorp/aws`) |
| `api.confluent.cloud` | Confluent Cloud resource management |
| `s3.amazonaws.com` / `s3.<region>.amazonaws.com` | State backend reads/writes |
| `dynamodb.<region>.amazonaws.com` | State backend locking |
| `sts.amazonaws.com` | OIDC role assumption |

> [!NOTE]
>
> Most failures here surface at the first `terraform init` as `Could not retrieve the list of available versions for provider hashicorp/aws: ... no such host` — that's `registry.terraform.io` unreachable. Verify access **before** merging the first agent PR.

> [!NOTE]
>
> **Air-gapped / proxied?** Use Terraform's native `.terraformrc` mirror — no Sariva-side change needed. The emitted Terraform keeps standard provider source addresses; redirection happens at the terraform CLI config layer (`provider_installation { network_mirror { url = "https://mirror.corp.example.com/terraform/" } direct { exclude = ["*/*"] } }`).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.