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

# Bootstrap GitOps and run first apply

> Push the scaffold and trigger the first Terraform apply after the Sariva platform is running.

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

ⓘINFO

**Setup wizard → Steps 5 & 1.** The wizard generated the Terraform scaffold (Step 5 — initial scaffold) and — on the GitHub Actions path — the workflow templates + watcher choice (the CI/CD applier inside Step 1 — deployment path). This page is where you push them and trigger the first apply.

With the [state backend](https://sariva.mintlify.site/install-setup/state-backend.md), [CI → AWS auth](https://sariva.mintlify.site/install-setup/ci-aws-auth.md), Helm deployment, and admin bearer validation complete, you bootstrap the GitOps scaffold: push it, then let CI apply it. This is the **initial** apply — not your whole estate. Growth operations (add stage / env / cluster) happen later through Slack and PRs.

ⓘINFO

**The agent generates Terraform; you own the workflow that applies it.** Every infrastructure change the Deployment Agent makes goes through a PR to your repo — the agent never applies infrastructure directly, and the Sariva platform never touches files under `.github/workflows/`.

✓SUCCESS

**Deploy-first is intentional.** The Sariva platform can run while a declared Confluent Cloud cluster is still awaiting Terraform output and credentials. Having the platform online before the first apply lets the watcher auto-register the cluster when enabled, and gives the CLI a running REST API for manual `sariva cluster register`.

ⓘINFO

This is the **GitHub Actions** path — the supported CI today. If you run a **different CI system** (GitLab CI, Jenkins, ArgoCD, kubectl-only), apply the emitted Terraform from your own pipeline against the same S3 state backend, then continue to [Connecting Kafka clusters](https://sariva.mintlify.site/connecting-clusters/overview.md).

## 1. Push the scaffold (inert)

The wizard emitted a GitOps scaffold under `sariva-gitops/`. For this step, copy only the Terraform code that should live in your infrastructure repo:

* `modules/`
* your stage directory, for example `dev/`

Do **not** copy `workflow_templates/` in this step. Workflow templates are activated in the next step.

For a `dev` stage, the copy looks like this:

```bash theme={null}
export WIZARD_DIR="/path/to/wizard-output"
export INFRA_REPO="/path/to/your-infra-repo"
export SARIVA_STAGE="dev"

cd "$INFRA_REPO"

# Copy the reusable Terraform modules.
mkdir -p modules
cp -R "$WIZARD_DIR/sariva-gitops/modules/." modules/

# Copy the selected stage directory, for example dev/.
mkdir -p "$SARIVA_STAGE"
cp -R "$WIZARD_DIR/sariva-gitops/${SARIVA_STAGE}/." "$SARIVA_STAGE/"

git status
git add modules "$SARIVA_STAGE"
git commit -m "chore: add Sariva Terraform scaffold"
git push origin main
```

After this push, your repo should contain a layout similar to:

```text theme={null}
your-infra-repo/
├── modules/
└── <stage>/              # for example: dev/
    └── <environment>/
        ├── configs/
        │   └── kafka_clusters.yaml
        └── clusters/
            └── <cluster>/
```

Pushing these files alone **runs nothing** because `.github/workflows/` has not been activated yet.

## 2. Activate the workflow

⚠WARNING

Copying the workflow file makes the workflow available in GitHub Actions. It does **not always start a run by itself**. The generated workflow usually runs on `push` only when files under your stage directory or `modules/` change. If this commit only adds `.github/workflows/terraform_apply_<stage>.yml`, use the manual `workflow_dispatch` run in the next step.

The wizard emitted the workflow YAMLs under `sariva-gitops/workflow_templates/terraform_apply_<stage>.yml`. They are **not** active until you copy the required file into `.github/workflows/` in your infrastructure repo.

For the same `dev` stage used above:

```bash theme={null}
export WIZARD_DIR="/path/to/wizard-output"
export INFRA_REPO="/path/to/your-infra-repo"
export SARIVA_STAGE="dev"

cd "$INFRA_REPO"
mkdir -p .github/workflows

cp "$WIZARD_DIR/sariva-gitops/workflow_templates/terraform_apply_${SARIVA_STAGE}.yml" \
  ".github/workflows/terraform_apply_${SARIVA_STAGE}.yml"

git add .github/workflows/
git commit -m "chore: activate Sariva Terraform apply workflow"
git push origin main                  # makes the workflow available in GitHub Actions
```

If your wizard generated more than one stage, repeat this activation step for each stage you want CI to manage.

ⓘINFO

Copying them in by hand (rather than letting the agent do it) is your chance to inspect the workflow before it becomes active CI — read the trust policy, verify the OIDC role ARNs, confirm the path filter matches your stage directory. Once committed, the workflows are customer-owned; subsequent agent PRs don't touch them.

After the workflow is active, start the first apply manually from GitHub Actions unless your activation commit also changed files under `<stage>/` or `modules/`.

## 3. Run the first apply manually

Open the workflow in GitHub:

```text theme={null}
GitHub repo → Actions → terraform-apply → Run workflow → Branch: main → Run workflow
```

This uses the workflow's `workflow_dispatch` trigger and runs the first `terraform apply` against the scaffold you already pushed.

If you use the GitHub CLI, you can run the same workflow with:

```bash theme={null}
export GITHUB_OWNER="<github-owner>"
export GITHUB_REPO="<gitops-repo>"
export SARIVA_STAGE="dev"

gh workflow run "terraform_apply_${SARIVA_STAGE}.yml" \
  --repo "${GITHUB_OWNER}/${GITHUB_REPO}" \
  --ref main
```

ⓘINFO

The generated workflow has three triggers: pull requests for plan, push to `main` for apply when `<stage>/` or `modules/` change, and `workflow_dispatch` for manual apply. Because the scaffold was pushed before the workflow file existed, the safest first run is the manual **Run workflow** action. Future changes under `<stage>/` or `modules/` can trigger automatically on push or merge.

After the run starts, GitHub Actions executes Terraform layer by layer:

```text theme={null}
<stage> → <stage>/<environment> → <stage>/<environment>/clusters/<cluster>
```

For the default example:

```text theme={null}
dev → dev/dev_env → dev/dev_env/clusters/dev_cluster
```

## 4. Verify watcher registration

**1. Outputs uploaded**

After apply succeeds, the workflow uploads `terraform output -json` as artifact `tf-outputs-<stage>`.

**2. Watcher registers the Kafka cluster**

If the [watcher](https://sariva.mintlify.site/concepts/gitops-loop.md) is enabled (`workflow_watcher.enabled: true`), the Sariva platform polls the successful workflow run, downloads the Terraform output artifact, and registers the Kafka cluster record for you.

**3. Kafka credential is still pending**

Registration only creates the Kafka cluster record. It does **not** attach broker credentials. The expected first state is `CRED_LIFECYCLE=awaiting_credentials`.

ⓘINFO

`awaiting_credentials` is expected after the first apply. The Confluent Cloud Kafka cluster now exists and Sariva knows about it, but Sariva still needs a credential reference before it can read metadata and observability data from the Kafka cluster. The next page, [Connecting Kafka clusters](https://sariva.mintlify.site/connecting-clusters/overview.md), explains the full registration and credential-attachment flow.

To verify that the watcher registered the Kafka cluster, first port-forward the Sariva platform service from another terminal:

```bash theme={null}
export RELEASE_NS="sariva-platform"
export SARIVA_SERVICE="$(kubectl -n "$RELEASE_NS" get svc \
  -l app.kubernetes.io/instance=sariva-platform,app.kubernetes.io/name=sariva-platform \
  -o jsonpath='{.items[0].metadata.name}')"

kubectl -n "$RELEASE_NS" port-forward "svc/${SARIVA_SERVICE:-sariva-platform}" 8000:8000
```

Then list registered Kafka clusters from your laptop:

```bash theme={null}
export SARIVA_PLATFORM_API_KEY="sariva_<generated-admin-bearer>"
sariva cluster list --api-url http://127.0.0.1:8000
```

Expected result before credentials are attached:

```text theme={null}
┏━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ALIAS       ┃ STATE   ┃ CRED_LIFECYCLE       ┃ NEXT_ACTION                                                                               ┃
┡━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ dev_cluster │ unknown │ awaiting_credentials │ DM Sariva: 'create observability credential for cluster dev_cluster, store in <provider>' │
└─────────────┴─────────┴──────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────┘
```

⚠WARNING

Do not treat `awaiting_credentials` as a failed apply. It means the watcher registered the Kafka cluster metadata, but the Kafka API key/secret has not been attached yet. Continue to [Connecting Kafka clusters](https://sariva.mintlify.site/connecting-clusters/overview.md) to create or reference the credential and move the Kafka cluster to `resolved`.

If the Kafka cluster does not appear, wait for the watcher polling interval and check the Sariva platform logs. If it still does not appear, continue to [Connecting Kafka clusters](https://sariva.mintlify.site/connecting-clusters/overview.md) and use the manual **REST registration** command for the Kafka cluster.

After this, growth operations (add stage / environment / Kafka cluster) happen through the same GitOps loop: Sariva opens a PR, GitHub Actions applies it, and the watcher reconciles the result.

## Continue the deployment path

> [card] [Next: connect Confluent Cloud clusters](https://sariva.mintlify.site/connecting-clusters/overview.md)
>
> Register or patch the applied cluster, attach credentials, and pass credential resolution.

> [card] [Back to deployment path](https://sariva.mintlify.site/deploy/aws-eks-cc.md)
>
> Return to the supported deployment path checklist.


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