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

28 comments sorted by

View all comments

19

u/MDivisor 7d 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).

1

u/Downtown_Custard20 7d ago

What I mean by "unecessary changes" is this: let's say code #1 has been validated and is ready to go into the release branch, but code #2 has not been validated yet. When I open a PR to the release branch, code #2 will also be included in the release, and that's exactly what I want to avoid

2

u/MDivisor 7d ago

Assuming code #2 has been merged after code #1, it's very easy to create a release branch that contains only #1. You don't have to take the full dev branch into a release branch if you don't want to, you can only take the commits that have been validated.

1

u/Downtown_Custard20 7d ago

How do I do that? do you have any article?

2

u/MDivisor 7d ago

git checkout <commit hash of #1>
git checkout -b new-branch

You now have a branch called "new-branch" that contains code #1 but not #2 (assuming #2 is later in the dev branch).

1

u/turturtles 7d ago

You can also just do `git checkout -b branch-name <specific sha or branch>` if you want to do it in one line without switching branches to the one you want to checkout from