pants for terraform has been quiet and stale for a...
# general
b
pants for terraform has been quiet and stale for a while: github.com/pantsbuild/pants/issues/21119 be honest, is there any real benefit to using pants to wrap tf other than just a single point of entry CLI (pants)? for straightforward terraform repos (I know, hard to believe) my first reaction is it seems like the added layer would be too confusing for maintainers that aren't both a TF expert + pants expert. Am I missing something obvious?
g
My off the cuff take, not claiming any authority here: for a repo that's only Terraform, I don't think the benefit clears the overhead. Pants earns its keep when you have multiple languages, shared deps, and fine grained caching/invalidation across a big target graph. Strip that away and you're mostly paying the setup and maintenance cost for a nicer entry point CLI. And the maintainer cost you called out is real. Needing to know both TF and Pants to debug the build is a steep ask for a repo where terraform fmt/validate/plan already gets you most of the way.
gratitude thank you 2
b
thanks Jason, appreciate the honesty! fwiw I'm enjoying Pants so far (still pretty new to it) in python+typescript+shell codebases, but your points are exactly what I was afraid of for this use case.
plus I can always tailor and migrate it to pants later if/when it makes more sense
g
It's possible that large terraform monorepos could value from it, but I'm not familiar enough with the pants backend for terraform to know what benefits would come from that.
d
we use it. with shared modules and such, the dependency graph is helpful to detect what is impacted by a change. Of course, you could just reapply everything since terraform is ~mostly idempotent. But I'm not sure we'll stick with it long term. Fortunately, pants is such a thin layer that it's an easy to swap to manually running terraform. You have to solve some of things that pants provides like ensuring that everyone is on the same terraform/linter/etc version, though, another way.
this 1
👀 1
g
The dependency graph is the specific thing I was thinking when I said a large terraform monorepo because exactly this ^^.
smaller repos you can just keep applying because of the idempotency.
larger ones it becomes an actual cost to keep blindly running applies across a whole bunch of infra.
d
yeah deifnitely
b
and I'm assuming pants doesn't
-target
apply regularly (brings TF shame) but rather for example let's say the repo has dozens or hundreds of different "apply-able" directories, aka environments, and each one of those sources many dozens of TF modules too.. then pants determines if only ~3 environments changed (or their upstream dependency modules) and therefore only terraform applies those?
g
@bright-orange-25107 I've not used the terraform backend, but assuming it mimics other source code backends, that would be true.
You can quite literally say, "show me everything that has changed as a result of change X." and then run apply against those. It probably will still require some hand stitching, but pants can at least answer the question of what changed and do so transitively.
For example, if a module changes in a commit and 15 environments depend on that module, you would be able to get the list of the 15 environments from pants.
The stitching comes in because pants will just tell you, "all of this crap has potentially been impacted by commit X" and you have to extrapolate what paths are actually important for deployment.
So in our repo we have 50K+ python source files across 200 python modules and when a change comes in we know exactly what to test and ship as a result of that graph pants has of our source and the relationship to the change.
d
yeah @bright-orange-25107 that's correct - you need to model each one as a separate terraform_deployment() to get similar functionality. which would be very disruptive if your team is used to a mono-deployment with targeted applies.
g
oh you see, I don't know the specifics of the terraform backend. Seems like more functionality is built out than I assumed or knew.
b
yeah @dazzling-pizza-75442 that's what I was thinking of. for terraform specifically, pants' dependency graph isn't an excuse for bad TF repo layout, like putting everything into just 1 or a few deployable environments because that would end up needing to terraform apply against a huge number of resources and defeat the benefits of pants (and just has a large blast radius in general)
👍🏻 1
👍 1
p
Slightly related: In our company we use Pulumi (python) via Pants (using a custom plugin), and I think that makes more sense than terraform because the pulumi code it runs is just normal python code in the same resolve and code tree, and is managed by Pants like all the other python code in the repo. We are quite happy with the arrangement.
f
As the person who wrote the Terraform backend initially while I was Toolchain, I wrote it as a proof of concept for using Pants to manage something that was not traditional source code. The original backend PR only provided fmt and lint goals. Others extended the backend for actually applying state.
😎 3
g
When were using a build tool to manage terraform (please not pants) the main benefit we found from it was the ability to have the build system assemble information and have it stored there instead of in terraform files The build system because the source of truth for a lot of stuff and we also used it to generate some files for TF. For us this was very valuable but YMMV