Context
The Terraform workspace lives only on a local branch (feat/terraform-org-management in C:/dev/ktsu-dev/infrastructure). It has no remote, no CI, and therefore no drift detection. Drift detection is the actual mechanism that keeps settings synchronized, so without it this work is a one-time convergence rather than ongoing management.
Work
- Create
ktsu-dev/infrastructure as a private repo and push the branch.
- Create an Azure service principal with a federated credential so Actions can reach the state backend over OIDC. State lives in the existing
ktsuhomelabtfstate storage account, tfstate container, key ktsu-dev-github.tfstate, alongside an unrelated homelab.tfstate.
- Set four repository secrets:
GH_ORG_TOKEN (needs admin:org and repo), AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID. The default GITHUB_TOKEN cannot manage other repositories.
- Add
.github/workflows/terraform.yml: PR runs plan and posts it as a comment, push to main runs apply, and a nightly scheduled job runs plan -detailed-exitcode and fails on drift.
- Verify drift detection actually fires. Set
has_wiki=true on one repo through the API, confirm the nightly job fails, then revert. A drift check that has never failed is not known to work.
Acceptance criteria
Note
github/.terraform.lock.hcl is committed and pins the provider to 6.13.0. Keep it that way. Without it, CI resolves the provider non-deterministically inside ~> 6.0, and three attributes currently in use are already deprecated, so a silent float could turn warnings into removals.
Context
The Terraform workspace lives only on a local branch (
feat/terraform-org-managementinC:/dev/ktsu-dev/infrastructure). It has no remote, no CI, and therefore no drift detection. Drift detection is the actual mechanism that keeps settings synchronized, so without it this work is a one-time convergence rather than ongoing management.Work
ktsu-dev/infrastructureas a private repo and push the branch.ktsuhomelabtfstatestorage account,tfstatecontainer, keyktsu-dev-github.tfstate, alongside an unrelatedhomelab.tfstate.GH_ORG_TOKEN(needsadmin:organdrepo),AZURE_CLIENT_ID,AZURE_TENANT_ID,AZURE_SUBSCRIPTION_ID. The defaultGITHUB_TOKENcannot manage other repositories..github/workflows/terraform.yml: PR runsplanand posts it as a comment, push tomainrunsapply, and a nightly scheduled job runsplan -detailed-exitcodeand fails on drift.has_wiki=trueon one repo through the API, confirm the nightly job fails, then revert. A drift check that has never failed is not known to work.Acceptance criteria
mainappliesNote
github/.terraform.lock.hclis committed and pins the provider to 6.13.0. Keep it that way. Without it, CI resolves the provider non-deterministically inside~> 6.0, and three attributes currently in use are already deprecated, so a silent float could turn warnings into removals.