terraform/scripts/syncdeps.sh
Martin Atkins 5811be26f8 go.mod: Separate modules at code ownership boundaries
Historically it's been hard for us to keep on top of dependency upgrades
as a matter of course because it's unclear which code owners might be
affected by or responsible for an upgrade of each module.

After trying a few different techniques to try to mitigate this, the most
promising one seems to be to tell the Go toolchain that each of these
components is a separate Go module, but then to stitch them all back
together again using replace directives so that we can mostly ignore these
module boundaries in everyday development.

The one case where we _do_ need to pay attention to these boundaries is
also the case where the separation is useful: upgrading a dependency of
any one of these modules might potentially force upgrading it for another
module too, and so the Go toolchain will help us notice that interaction
and we can immediately which code owners might need to be involved in
reviewing and testing that particular upgrade.

To make that process less onerous, this adds a new makefile target
"make syncdeps" which runs "go mod tidy" in all of the modules at once
and thus forces the toolchain to align their dependencies to the extent
required for them all to be linked together successfully, and to generate
go.mod and/or go.sum diffs that will match our configured code ownership
paths to trigger the appropriate code review requests.

Hopefully before too long we'll be able to move all the backends out into
provider plugins and delete the "legacy" module entirely and then this
oddness won't be needed anymore, but as long as we're all trying to play
together in this same sandbox this is a small amount of extra ceremony in
return for hopefully reducing the level of anxiety involved in keeping the
system's dependencies up to date more consistently.
2024-03-11 08:34:46 -07:00

28 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
# This repository contains one logical codebase but as an implementation detail
# it's split into multiple modules at the boundaries of code ownership, so
# that we can keep track of which dependency changes might affect which
# components.
#
# This script runs "go mod tidy" in each module to synchronize any dependency
# updates that were made in any one of the modules.
set -eufo pipefail
# We'll do our work in the root of the repository, which is the parent
# directory of where this script is.
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
# We need to make sure the root go.mod is synchronized first, because otherwise
# the "go list" command below might fail.
go mod tidy
# Each of the modules starting at our root gets its go.mod and go.sum
# synchronized, so that we can see which components are affected by an
# update and therefore which codeowners might be interested in the change.
for dir in $(go list -m -f '{{.Dir}}' github.com/hashicorp/terraform/...); do
(cd $dir && go mod tidy)
done