> ## 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.

# AWS S3/DynamoDB state with GitHub Actions

> Collect an AWS S3 Terraform state bucket and DynamoDB lock table, then create the IAM role GitHub Actions assumes to run Terraform.

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

ⓘINFO

**Wizard steps satisfied.** This page satisfies **Wizard Step 6 — Terraform state backend** and prepares the **CI/CD applier** answer in **Wizard Step 1 — Deployment path**. When you run the wizard, enter the bucket name, lock table name, AWS region, GitHub repository, and role ARN prepared here.

⚠WARNING

**Do not continue with the wizard until you know the S3 bucket name, DynamoDB lock table name, and AWS region.** These are required inputs for **Wizard Step 6 — Terraform state backend**. In most organizations, these values are provided by the AWS/platform team. The optional helper commands at the end of this page are only for teams that do not already have an approved Terraform state backend.

Use this task when your deployment path includes:

```text theme={null}
CI executor: GitHub Actions
Terraform state backend: AWS S3 + DynamoDB
CI cloud access: GitHub Actions assumes an AWS IAM role through OIDC
```

This page creates the **customer-owned CI runner IAM role**. It is not the same identity as the Sariva platform pod identity.

| Identity | Runs where | Purpose |
| - | - | - |
| **GitHub Actions OIDC role** | GitHub runner | Runs Terraform, owns Terraform state access, reads the Kafka admin secret, and writes the observability secret. |
| **EKS Pod Identity role** | Sariva platform pod | Reads the observability secret at runtime. It does not read the admin Kafka key. |

ⓘINFO

**Keep the two GitHub credentials separate.** The **Sariva platform GitHub token** lets Sariva open pull requests in your GitOps repository. The **GitHub Actions AWS role** lets GitHub Actions access AWS resources such as the S3 state bucket, DynamoDB lock table, and selected AWS credential-store paths. They are different credentials with different purposes.

## 1. Collect the state backend details

Ask the AWS/platform team for these values before running the setup wizard.

| Value | Example | Used by |
| - | - | - |
| AWS account ID | `123456789012` | IAM role and policy ARNs |
| AWS region | `us-east-1` | S3/DynamoDB/Terraform backend |
| S3 state bucket | `acme-dev-sariva-tf-state` | Terraform state storage |
| DynamoDB lock table | `acme-dev-sariva-tf-lock` | Terraform state locking |
| GitHub owner | `acme-corp` | OIDC trust policy |
| GitHub repo | `sariva-gitops` | OIDC trust policy and GitHub secrets |
| Stage name | `dev` | Role naming, IAM scoping, and wizard input |

Set local variables for the commands below. Replace the example values with your customer/project values:

```bash theme={null}
export AWS_REGION="us-east-1"
export AWS_ACCOUNT_ID="$(aws sts get-caller-identity --query Account --output text)"

export GITHUB_OWNER="<github-owner>"
export GITHUB_REPO="<gitops-repo>"
export SARIVA_STAGE="dev"

export TF_STATE_BUCKET="acme-nonprod-tf-state"
export TF_LOCK_TABLE="acme-nonprod-tf-lock"
export GHA_ROLE_NAME="${SARIVA_STAGE}-gha-terraform-deploy-role"
```

These variables are used only by the helper commands on this page. The setup wizard will ask you for the same state bucket, lock table, region, GitHub repository, and role ARN later.

## 2. Validate the existing S3 bucket and DynamoDB table

Check that the S3 bucket exists in the expected region:

```bash theme={null}
aws s3api get-bucket-location \
  --bucket "$TF_STATE_BUCKET" \
  --query 'LocationConstraint' \
  --output text
```

For `us-east-1`, AWS may return `None` or an empty value. For other regions, the output should match `$AWS_REGION`.

Check versioning:

```bash theme={null}
aws s3api get-bucket-versioning --bucket "$TF_STATE_BUCKET"
```

Expected result:

```json theme={null}
{
  "Status": "Enabled"
}
```

Check encryption:

```bash theme={null}
aws s3api get-bucket-encryption --bucket "$TF_STATE_BUCKET"
```

Expected result: the bucket has default server-side encryption enabled.

Check public access block:

```bash theme={null}
aws s3api get-public-access-block --bucket "$TF_STATE_BUCKET"
```

Expected result: all four public access block settings are `true`.

Check the DynamoDB lock table:

```bash theme={null}
aws dynamodb describe-table \
  --table-name "$TF_LOCK_TABLE" \
  --region "$AWS_REGION" \
  --query 'Table.{TableName:TableName,Status:TableStatus,BillingMode:BillingModeSummary.BillingMode,KeySchema:KeySchema}'
```

Expected result:

* table status is `ACTIVE`
* billing mode is `PAY_PER_REQUEST`
* hash key is `LockID`

!DANGER

**Stop if validation fails.** Do not run the setup wizard with guessed bucket or table values. If the backend details are wrong, the first Terraform run fails at `terraform init`, and the generated GitOps workflow will not be able to manage infrastructure.

## 3. Confirm the GitHub OIDC provider in AWS

GitHub Actions should authenticate to AWS through OIDC instead of static AWS access keys.

Check whether the provider already exists:

```bash theme={null}
aws iam list-open-id-connect-providers \
  --query 'OpenIDConnectProviderList[?contains(Arn, `token.actions.githubusercontent.com`)].Arn' \
  --output text
```

If the command returns nothing, create the provider:

```bash theme={null}
aws iam create-open-id-connect-provider \
  --url https://token.actions.githubusercontent.com \
  --client-id-list sts.amazonaws.com \
  --thumbprint-list 6938fd4d98bab03faadb97b34396831e3780aea1
```

Expected result: AWS has an OIDC provider for `token.actions.githubusercontent.com`.

## 4. Create the GitHub Actions Terraform deploy role

Create `trust-policy.json`:

```bash theme={null}
cat > trust-policy.json <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::${AWS_ACCOUNT_ID}:oidc-provider/token.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
        },
        "StringLike": {
          "token.actions.githubusercontent.com:sub": "repo:${GITHUB_OWNER}/${GITHUB_REPO}:*"
        }
      }
    }
  ]
}
EOF
```

Create the role:

```bash theme={null}
aws iam create-role \
  --role-name "$GHA_ROLE_NAME" \
  --assume-role-policy-document file://trust-policy.json

export AWS_ROLE_TO_ASSUME="$(aws iam get-role \
  --role-name "$GHA_ROLE_NAME" \
  --query 'Role.Arn' \
  --output text)"

echo "$AWS_ROLE_TO_ASSUME"
```

!DANGER

**Do not use a broad GitHub OIDC trust policy.** For production, narrow the trust policy to a protected branch or environment, for example `repo:<owner>/<repo>:ref:refs/heads/main` or `repo:<owner>/<repo>:environment:production`.

## 5. Grant the role access to Terraform state

Create `terraform-state-policy.json`:

```bash theme={null}
cat > terraform-state-policy.json <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "TerraformStateBucket",
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation",
        "s3:GetBucketVersioning",
        "s3:GetEncryptionConfiguration"
      ],
      "Resource": "arn:aws:s3:::${TF_STATE_BUCKET}"
    },
    {
      "Sid": "TerraformStateObjects",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::${TF_STATE_BUCKET}/*"
    },
    {
      "Sid": "TerraformStateLock",
      "Effect": "Allow",
      "Action": [
        "dynamodb:GetItem",
        "dynamodb:PutItem",
        "dynamodb:DeleteItem",
        "dynamodb:DescribeTable"
      ],
      "Resource": "arn:aws:dynamodb:${AWS_REGION}:${AWS_ACCOUNT_ID}:table/${TF_LOCK_TABLE}"
    }
  ]
}
EOF
```

Attach it to the GitHub Actions role:

```bash theme={null}
aws iam put-role-policy \
  --role-name "$GHA_ROLE_NAME" \
  --policy-name terraform-state-and-lock \
  --policy-document file://terraform-state-policy.json
```

✓SUCCESS

**This role now has Terraform backend access.** The role can read and write the Terraform state object in S3 and use the DynamoDB lock table. Keep this base policy small, then add credential-store permissions only when the selected path needs them.

## 6. Add credential-store permissions when using AWS Secrets Manager or SSM

The base role above is enough for Terraform state only. If this deployment path stores Kafka credentials in **AWS Secrets Manager** or **AWS SSM Parameter Store**, the GitHub Actions role also needs access to the credential-store paths.

ⓘINFO

**Credential source and Kafka credential store are different.** `credentialSource` is where GitHub Actions reads CI inputs such as `CONFLUENT_CLOUD_API_KEY`. The **Kafka credential store** is where per-Kafka-cluster admin and observability credentials live after the Kafka cluster exists.

### Required when using AWS Secrets Manager as the Kafka credential store

GitHub Actions needs to:

* **read** the manually-created Kafka admin key from `<stage>/<env>/clusters/<cluster>/kafka-admin` so Terraform can configure topics, ACLs, and cluster-layer resources;
* **write** the Sariva-created observability key to `<stage>/<env>/clusters/<cluster>/observability-reader`;
* call `GetResourcePolicy` during Terraform create/refresh. Without it, the apply can fail after the Secret shell is created and before the value is written.

Create an additional policy for the same GitHub Actions role:

```bash theme={null}
cat > kafka-credentials-secretsmanager-policy.json <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadAndManageStageKafkaCredentialSecrets",
      "Effect": "Allow",
      "Action": [
        "secretsmanager:CreateSecret",
        "secretsmanager:DescribeSecret",
        "secretsmanager:GetSecretValue",
        "secretsmanager:PutSecretValue",
        "secretsmanager:TagResource",
        "secretsmanager:GetResourcePolicy",
        "secretsmanager:UpdateSecret",
        "secretsmanager:DeleteSecret",
        "secretsmanager:ListSecretVersionIds"
      ],
      "Resource": "arn:aws:secretsmanager:${AWS_REGION}:${AWS_ACCOUNT_ID}:secret:${SARIVA_STAGE}/*/clusters/*"
    }
  ]
}
EOF

aws iam put-role-policy \
  --role-name "$GHA_ROLE_NAME" \
  --policy-name kafka-credentials-secretsmanager \
  --policy-document file://kafka-credentials-secretsmanager-policy.json
```

⚠WARNING

**The GitHub Actions role and the pod AWS identity need different permissions.** The GitHub Actions role reads the admin credential and writes the observability credential during Terraform apply. The Sariva platform pod reads only the observability credential at runtime. Do not grant the pod access to the admin Kafka key.

### Required when using AWS SSM Parameter Store as the Kafka credential store

If the Kafka credential store is AWS SSM Parameter Store, grant the GitHub Actions role permission to read the admin parameter and write the observability parameter. Add KMS permissions when SecureString parameters use a customer-managed KMS key.

```json theme={null}
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadAndWriteStageKafkaCredentialParameters",
      "Effect": "Allow",
      "Action": ["ssm:GetParameter", "ssm:PutParameter"],
      "Resource": "arn:aws:ssm:<REGION>:<ACCOUNT>:parameter/<stage>/*/clusters/*"
    },
    {
      "Sid": "UseKmsForSecureStringWhenUsingCustomerManagedKey",
      "Effect": "Allow",
      "Action": ["kms:Encrypt", "kms:Decrypt", "kms:GenerateDataKey"],
      "Resource": "arn:aws:kms:<REGION>:<ACCOUNT>:key/<kms-key-id>"
    }
  ]
}
```

### Matching pod read permission

The Sariva pod reads the **observability** credential at runtime. Configure the pod AWS identity on [Wire the pod's AWS identity](https://sariva.mintlify.site/install-setup/irsa.md) so it can read only the observability leaf:

```text theme={null}
AWS Secrets Manager: arn:aws:secretsmanager:<REGION>:<ACCOUNT>:secret:<stage>/*/clusters/*/observability-reader*
AWS SSM:             arn:aws:ssm:<REGION>:<ACCOUNT>:parameter/<stage>/*/clusters/*/observability-reader
```

## 7. Add the AWS role ARN as a GitHub Actions secret

The generated workflow assumes the AWS role through OIDC, so it needs the role ARN as a repository secret. This is an AWS-auth secret and is required regardless of where your Confluent Cloud credentials live.

### Option A — GitHub UI

Use this option if you do not have the GitHub CLI installed.

1. Open the GitHub repository that will hold the Sariva GitOps scaffold.
2. Go to **Settings**.
3. Go to **Secrets and variables**.
4. Select **Actions**.
5. Select **New repository secret**.
6. Add the following secret.

| Secret name | Value |
| - | - |
| `AWS_ROLE_TO_ASSUME` | The role ARN printed in Step 4 |

### Option B — GitHub CLI

Use this option only if `gh` is installed and authenticated.

```bash theme={null}
gh secret set AWS_ROLE_TO_ASSUME \
  --repo "$GITHUB_OWNER/$GITHUB_REPO" \
  --body "$AWS_ROLE_TO_ASSUME"
```

ⓘINFO

**The Confluent Cloud OrganizationAdmin key is set separately.** Where it lives depends on your credential source — GitHub Actions secrets or AWS SSM Parameter Store — so it is not always a GitHub secret. Set it on [Confluent Cloud credentials for CI](https://sariva.mintlify.site/install-setup/access-and-state/cc-ci-credentials.md), which forks by your `credentialSource` choice. The Confluent Cloud metrics key is different again: it goes into the Sariva runtime Secret so the platform pod can read metrics.

## 8. Validate the role and AWS secret

Validate the role:

```bash theme={null}
aws iam get-role --role-name "$GHA_ROLE_NAME" \
  --query 'Role.{RoleName:RoleName,Arn:Arn}'

aws iam list-role-policies --role-name "$GHA_ROLE_NAME"
```

If you used the GitHub UI, confirm the secret name in:

```text theme={null}
GitHub repo → Settings → Secrets and variables → Actions → Repository secrets
```

If you used the GitHub CLI, run:

```bash theme={null}
gh secret list --repo "$GITHUB_OWNER/$GITHUB_REPO"
```

Expected from this page before the first Terraform apply:

```text theme={null}
AWS_ROLE_TO_ASSUME
```

The Confluent Cloud `CONFLUENT_CLOUD_API_KEY` / `CONFLUENT_CLOUD_API_SECRET` inputs are set and validated on [Confluent Cloud credentials for CI](https://sariva.mintlify.site/install-setup/access-and-state/cc-ci-credentials.md) — as GitHub secrets or SSM parameters depending on your credential source. Per-Kafka-cluster admin and observability credentials are not GitHub Actions secrets in the AWS-native credential-store path; they live in AWS Secrets Manager or SSM.

## 9. Values to enter in the setup wizard

When the wizard asks for Terraform state and CI authentication, enter the values you prepared here.

| Wizard input | Value |
| - | - |
| State backend mode | `byob` |
| State bucket | `$TF_STATE_BUCKET` |
| Lock table | `$TF_LOCK_TABLE` |
| State region | `$AWS_REGION` |
| AWS auth method | `oidc` |
| AWS role to assume | `$AWS_ROLE_TO_ASSUME` |
| Credential source | `github_secrets`, unless you intentionally choose AWS SSM or another supported provider |
| GitHub repo | `$GITHUB_OWNER/$GITHUB_REPO` |
| Base branch | `main` or your selected default branch |

## Optional helper: create a new state bucket and lock table

> [accordion] Create a new S3 bucket and DynamoDB lock table if your platform team did not provide one
>
> Use this only when your organization does not already have an approved Terraform state backend for Sariva.
>
> ```bash theme={null}
> if [ "$AWS_REGION" = "us-east-1" ]; then
>   aws s3api create-bucket \
>     --bucket "$TF_STATE_BUCKET" \
>     --region "$AWS_REGION"
> else
>   aws s3api create-bucket \
>     --bucket "$TF_STATE_BUCKET" \
>     --region "$AWS_REGION" \
>     --create-bucket-configuration LocationConstraint="$AWS_REGION"
> fi
>
> aws s3api put-bucket-versioning \
>   --bucket "$TF_STATE_BUCKET" \
>   --versioning-configuration Status=Enabled
>
> aws s3api put-bucket-encryption \
>   --bucket "$TF_STATE_BUCKET" \
>   --server-side-encryption-configuration \
>   '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'
>
> aws s3api put-public-access-block \
>   --bucket "$TF_STATE_BUCKET" \
>   --public-access-block-configuration \
>   BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
>
> aws dynamodb create-table \
>   --table-name "$TF_LOCK_TABLE" \
>   --attribute-definitions AttributeName=LockID,AttributeType=S \
>   --key-schema AttributeName=LockID,KeyType=HASH \
>   --billing-mode PAY_PER_REQUEST \
>   --region "$AWS_REGION"
> ```
>
> After creation, return to **Step 2** on this page and validate the backend.

## Continue the deployment path

> [card] [Next: Confluent Cloud credentials for CI](https://sariva.mintlify.site/install-setup/access-and-state/cc-ci-credentials.md)
>
> Provide the OrganizationAdmin Cloud API key to CI — as a GitHub secret or SSM parameter, per your credential source.

> [card] [Back to the deployment path](https://sariva.mintlify.site/deploy/aws-eks-cc.md)
>
> Return to the full path map if you want to confirm where this task fits.

If the state backend or OIDC role is wrong, the first visible failure usually appears during the GitHub Actions AWS credential step or during `terraform init`.


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