Step 2: Bootstrap
The one-time manual setup OpenTofu cannot do for itself — tokens, the state bucket, state passphrases and Cloudflare Zero Trust.
Goal: every credential and value GitHub Actions needs to run OpenTofu, written into your secret manager. You do this once; both environments share some of it.
Everything on this page is manual by necessity: OpenTofu needs these to exist before it can run. Record each value in your secret manager as you go; step 4 copies them into GitHub.
2.1 DigitalOcean API token
Control panel → API → Tokens → Generate New Token. Name it lynkoria-opentofu, choose an expiry you will track, and give it full read/write access (OpenTofu manages VPCs, Droplets, firewalls, tags, databases, App Platform, Spaces keys and registry credentials). Store it as DIGITALOCEAN_ACCESS_TOKEN.
You may use one token per environment for separation, or one shared token.
2.2 Spaces access key
Control panel → Spaces Object Storage → Access Keys → Create Access Key → Full access. OpenTofu uses it for its state bucket and to create the attachments bucket. Store the pair as SPACES_ACCESS_KEY_ID and SPACES_SECRET_ACCESS_KEY.
The API gets its own key limited to its bucket; OpenTofu creates that one (digitalocean_spaces_key in storage.tf).
2.3 State bucket
OpenTofu keeps its state (what exists, plus generated secrets, encrypted) in a private Spaces bucket. Create it once:
aws configure --profile do-spaces # the key from 2.2, region sgp1
s3() { aws --profile do-spaces --endpoint-url https://sgp1.digitaloceanspaces.com "$@"; } # works in bash and zsh
s3 s3api create-bucket --bucket YOUR_STATE_BUCKET
s3 s3api put-bucket-versioning --bucket YOUR_STATE_BUCKET --versioning-configuration Status=EnabledChoose a unique name such as lynkoria-tofu-state-<suffix>. Versioning keeps older state versions so a bad write can be recovered. Store the name as TOFU_STATE_BUCKET. The state files are lynkoria/zone.tfstate, lynkoria/staging.tfstate and lynkoria/production.tfstate.
2.4 State passphrases
OpenTofu encrypts state and plans client-side before they reach the bucket (encryption block in versions.tf, enforced). Generate three passphrases:
openssl rand -base64 33 # TOFU_ZONE_STATE_PASSPHRASE (zone stack)
openssl rand -base64 33 # TOFU_STATE_PASSPHRASE for staging
openssl rand -base64 33 # TOFU_STATE_PASSPHRASE for productionWithout the passphrase, OpenTofu cannot read its state, and the generated secrets in it (database passwords, signing keys, the scanner CA) are gone. Keep the passphrases in your secret manager with a backup. Do not change them by editing the variable; see rotation.
2.5 Cloudflare
-
Zone. The domain must be an active zone in Cloudflare (Add a site → change nameservers at the registrar). Note the Zone ID and Account ID from the zone's overview page.
-
Zero Trust organization (skip only if you deploy with
ENABLE_ACCESS=false; Access is what gives the console MFA, see manual deployment 1.6). Open Zero Trust once and choose a team name. Your team domain isYOUR_TEAM.cloudflareaccess.com. Under Settings → Authentication, add your identity provider or enable one-time PIN, and require MFA at the IdP. -
API token. My Profile → API Tokens → Create Token → Create Custom Token, with these permissions:
Scope Permission (as shown in the token form) Level Used for Account Cloudflare Pages Edit Pages projects and custom domains; wrangler pages deployAccount Access: Apps and Policies Edit The console's Access application and policy Zone DNS Edit All DNS records Zone Zone Settings Edit TLS mode, Always Use HTTPS, WebSockets, … Zone Transform Rules Edit Origin-lock header rule Zone Cache Rules Edit API cache bypass Zone Single Redirect Edit www→ apex redirectSet Account Resources to your account and Zone Resources to
lynkoria.com.Can't find "Cloudflare Pages"? Cloudflare now shows Pages inside Workers & Pages in the dashboard, but the token permission is still named Cloudflare Pages (Cloudflare's permission list). In the Account row's permission dropdown, type
Pagesto filter. Do not pick Workers Scripts instead: it covers Workers, not Pages projects. If the option really isn't there, start from the Edit Cloudflare Workers template, check that its list includes Cloudflare Pages: Edit, and add the Access and zone permissions above.Store it as
CLOUDFLARE_API_TOKEN. If an apply fails with an authentication or permission error, the message names the resource; add the matching permission. -
Email Routing (optional). Enabling Email Routing for
security@andsupport@creates its own MX and SPF records. The zone stack manages DMARC and CAA only, so the two do not conflict.
2.6 SSH key and admin IPs
OpenTofu installs your SSH key on both Droplets and opens SSH only to your IPs.
doctl compute ssh-key import lynkoria-operator --public-key-file ~/.ssh/id_ed25519.pub
doctl compute ssh-key list --format ID,Name,FingerPrint
curl -s https://api.ipify.org; echoNote the key fingerprint and your IP as a /32 CIDR.
Verify
Your secret manager now holds: DIGITALOCEAN_ACCESS_TOKEN, SPACES_ACCESS_KEY_ID, SPACES_SECRET_ACCESS_KEY, TOFU_STATE_BUCKET, three passphrases, CLOUDFLARE_API_TOKEN, the Cloudflare account and zone IDs, the team domain, the SSH key fingerprint and your admin IP. The state bucket exists:
s3 s3api get-bucket-versioning --bucket YOUR_STATE_BUCKETNext: Step 3: Configure.
Step 1: Workstation
Install the tools, validate the checkout and the OpenTofu code offline, and make sure the container registry can hold Lynkoria's images.
Step 3: Configure
Review the per-environment OpenTofu settings — hostnames, product origins, LiveKit key references and sizes — and change them through a pull request.