After building a VPC by hand, I wanted to make a change in Git and see what it would do to the network before deploying it. For this NextWork project, I set up GitHub Actions to run a Terraform plan on pull requests and apply changes after a merge to main.
The project took me about eight hours. The error I spent the most time chasing came down to how I’d spelled my GitHub organization name.
The bucket had to exist first
Terraform keeps a state file so it can match the resources in my code to the ones in AWS. My plan was to keep that file in S3 so my laptop and the GitHub runner could work from the same state. That left me with a circular dependency. How could Terraform store its state in the bucket it was about to create?
I gave the bucket its own bootstrap configuration with local state. Once it existed, I could point the dev environment at it. I enabled versioning, encryption, and public access blocking on the bucket. I also wrote down why I chose S3’s native lockfile, which keeps two Terraform runs from writing state at the same time.
Breaking the VPC module on purpose
I wrote a reusable module for the public and private subnets across two Availability Zones. To test the address layout, I deliberately gave a public and a private subnet the same CIDR block. AWS rejected the overlap. I corrected the allocation so each subnet got its own range inside the VPC.
That error was easy to trace because I knew exactly what I’d changed. The one that followed wasn’t.
The typo I blamed on Terraform
I used OpenID Connect so GitHub Actions could get temporary AWS credentials. The IAM role’s trust policy checked which repository and branch the workflow came from before letting it assume the role.
When the workflow hit an error assuming the role, I thought I’d written the Terraform wrong. I’d actually mistyped my GitHub organization name. With the spelling corrected, the workflow could assume the role and run the deployment on merge.
If I saw that error again, I’d check which identity AWS expected and compare it with the workflow that actually ran. The error happened before Terraform had permission to change a single subnet.
Thanks for reading.
More field notes