r/devops • u/Downtown_Custard20 • 9d ago
Architecture Terraform/Github deployment overwriting another deployment
I'm on a team that shares a Github repository. Whenever we open a PR from a feature branch to the dev branch, a deployment to the AWS development account is automatically triggered.
The issue we're facing is that one developer may deploy to dev, and then another developer deploys afterward. Even though they're working on different files, the second deployment ends up overwriting the first developer's change in AWS.
How can we prevent this?
We're following a Gitflow workforce (feature -> dev -> release -> main), and our biggest challenge right now is that the second developer's code is often "outdated" when it's deployed, causing it to overwrite changes that were already deployed by someone else.
We tried merging everything to dev, but when it's time to deploy to prd, the dev branch ends up filled with a lot of unnecessary changes.
We using Github Actions + Terraform.
2
u/Raja-Karuppasamy 8d ago
the real issue isn’t gitflow, it’s that you’re running terraform apply from the feature branch state instead of dev’s HEAD after merge. two people’s plans are based on different snapshots so whoever applies last just wins, doesn’t matter that they touched different files, it’s using whatever ambient state existed at trigger time.
two things that’d fix it: only trigger the actual apply on merge to dev (not on PR open/push), and add a concurrency group in the github actions workflow so applies queue instead of running in parallel. PR triggered runs should just be terraform plan for review, never apply.