ci: run terraform plan/apply in CI via OIDC#86
Merged
Conversation
Add two OIDC roles in infra/terraform-ci.tf: lux-terraform-plan (ReadOnlyAccess, assumable from any ref) and lux-terraform-apply (curated least-privilege, main branch only). terraform.yml gains a plan job on PRs (read-only, -lock=false, written to the run summary); release.yml applies the infra when a release-please version-bump PR is merged (release_created), via the main-only apply role. Infra changes no longer apply from a laptop.
Replace the gitignored secrets.auto.tfvars variable with a data.aws_secretsmanager_secret_version read of lux/discord-public-key, so terraform plan/apply get the value in CI via OIDC and nothing is committed to this public repo. Grant the read-only plan role GetSecretValue on just that one secret; the apply role's secret:lux/* grant already covers it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves Terraform off the laptop:
planon PRs,applyon release — both in CI via OIDC, no local AWS creds.How it works
terraform.ymlrunsvalidate+ a realplan(read-onlylux-terraform-planrole,-lock=false) and writes the diff to the run summary, so changes are reviewable before merge.terraform-applyjob inrelease.yml, gated onrelease_created, runsterraform applywhen the release-please version-bump PR is merged (i.e. when a release is cut). It's the only place apply runs.Two roles (
infra/terraform-ci.tf)lux-terraform-planReadOnlyAccesslux-terraform-applyrefs/heads/mainonly — only a release apply can assume itThe apply policy is scoped per-service to lux's resources (IAM on
role/lux*+ thecargo-lambda-role-*, Lambda/Logs onlux*, DynamoDBlux-sync, Cognito, IoT in-account, Secrets Manager read onlux/*, and S3 state on thelux/prefix only).Policy validated (read-only, nothing mutated)
Verified with
iam:SimulateCustomPolicyagainst the real resource ARNs:CI can't create the role it then assumes, so the two roles must be created once by an admin:
Until that runs, this PR's own
planjob fails (the plan role doesn't exist yet) — expected. After the bootstrap, re-run the job (it'll pass) and merge. From then on every infra change flows through CI.