Let the agent write your team's first Terraform

You need:

  • The owner or admin role in the workspace. For anyone else, the step reads Only a workspace owner or admin can set up configuration as code.
  • The GitHub App installed on your code repositories and on the repository the configuration goes in. If it isn't, connect GitHub first.
  • A host serving the workspace, or a push pool that names an egress. If you have neither, run a host, or send push pool runs through an egress. A push pool that names no egress can't run the setup chat.
  • If the host or the egress has an egress allow-list, registry.terraform.io, github.com and release-assets.githubusercontent.com on it, so terraform init can download Spotlight's provider.

Start the setup chat

  1. In the Inbox, open Set up your team. Set up configuration as code shows a form once the GitHub App is installed, and a host serves the workspace or a push pool names an egress.
  2. From Repository, choose the repository the configuration goes in. Leave the folder as spotlight, or type the path of another folder from the repository root, as in infra/spotlight.
  3. Under Repositories, tick the code repositories the agent should read.
  4. Choose the agent. The form reads Spotlight lets this repository's GitHub Actions plan pull requests and apply its default branch. Click Start setup chat.

The chat opens on the Agent page, with every repository you chose checked out. If the folder or repository is rejected, a message at the bottom of the page says why, and the form keeps what you wrote.

A chat is seen only by the person who started it. If someone else on the team started the setup chat, the step says who, and the pull request link appears for everyone once it is open.

Check the trusts and repository variables

Before the chat starts, Spotlight reads the configuration repository's default branch and creates two OIDC trusts for the repository's GitHub Actions, with you as their creator:

  • github-pull-requests: a pull request may plan.
  • github-apply: a push to the default branch may apply, with the configure, secrets and runners scopes.

If trusts with these keys exist, for example from a setup with another repository, Spotlight changes them to match the repository you chose.

Spotlight then sets the repository variables SPOTLIGHT_URL, SPOTLIGHT_PLAN_TRUST and SPOTLIGHT_APPLY_TRUST. If the GitHub App does not have the permission Variables: read and write, Spotlight does not set them, and the pull request lists them for you to add. See Let the App set repository variables.

Talk it through

Answer the agent in the chat. It reports what it found in each repository and tool and what it would change from the built-in lines, and asks about anything unclear. The agent is briefed to call only the tools' read calls, and to draft nothing until you agree. A tool that needs approval is dismissed in a chat.

Review the pull request

The agent writes into the folder you chose:

  • the workspace's current configuration, one file for each concern, such as line-<team>-<line>.tf for each line, with each line's source naming its own file
  • the backend that keeps the Terraform state: the team's own, or Spotlight's when the team has none, and a README.md
  • a prompt file for each station, prompts/<team>/<line>/<station>.md, adapted to what it learned
  • each station's setup and check commands
  • a judge for each work station, with its claims written in the block: short statements that a good run at that station makes true for the team
  • skills adopted from the team's own rules files
  • a reviews policy from CODEOWNERS, and match hooks for risky paths
  • the two trusts as spotlight_oidc_trust resources, with import blocks

At the repository root, it adds the workflow .github/workflows/spotlight.yml. On a pull request that changes the folder, the workflow runs terraform fmt -check, terraform init, terraform validate and terraform plan through the github-pull-requests trust. On a push to the default branch, it runs terraform apply through the github-apply trust. When Spotlight keeps the state, each job first downloads spotlight and signs in to the state with spotlight token, through the same trust.

It runs terraform init, terraform fmt, terraform validate and terraform plan, signed in to Spotlight's state with the run's token when Spotlight keeps it, commits on a branch such as spotlight-configuration, and opens a pull request. The description lists each departure from the built-in lines with the files it rests on, the stations that have a judge and what their claims check, followed by the plan. The plan should import what already exists and change only what the agent adapted.

Set up configuration as code now has a check mark. Expand it and click Open pull request. The step reads GitHub Actions: pull requests in <repository> plan, and pushes to <defaultBranch> apply. If Spotlight could not set the variables, it also reads Add the repository variables that the pull request lists.

The agent never applies anything. Before you merge:

  1. In the repository's Settings, under Secrets and variables and then Actions, add what the pull request lists: the TF_VAR_ secrets, the credentials of the state backend if it is not Spotlight's, and the repository variables if Spotlight could not set them.
  2. Review the pull request and merge it. The workflow applies the configuration from the default branch.

If the default branch is not protected

If merging into the default branch needs no approving review, anyone who can push to it can change the workspace's configuration through the github-apply trust. The pull request says this first, and the step shows a warning icon.

On GitHub, protect the default branch with a branch protection rule or a ruleset that requires at least one approving review. Spotlight counts either as protection, and nothing less. Reading a branch protection rule needs the GitHub App's Administration read permission; without it, Spotlight sees only rulesets.

If the pull request has no plan

The agent opens the pull request without a plan when terraform init cannot download the provider. Its note in the chat says so. Add the three hosts above to the host's allow-list with spotlight host config set egress-allow=<list>, and ask the agent in the chat to plan again.

On this page