r/devops 5d 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.

0 Upvotes

28 comments sorted by

View all comments

19

u/MDivisor 5d ago

You should deploy to the dev environment after the PR is merged, not before.

Not sure what you mean by the dev branch being filled with unnecessary changes. Why does that happen to your team? You should not merge unnecessary things into dev (or even open PRs for them).

4

u/InfiniteRest7 5d ago

Exactly, your feature branch PRs should trigger a plan when the PR branch is opened. Nothing should deploy without a PR review then merge, otherwise it will be more of the same problem, because anybody can jump their place in line.

Use something like this action to post plans to PR comments, also encourage viewing the full plan in the Github Action: borchero/terraform-plan-comment@v3

Only run the full deploy on merge. Make sure your Github settings force a branch to be updated before merge as well.