pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.2k stars 618 forks source link

tailor for terraform should track lock files #14790

Closed ryanking closed 5 days ago

ryanking commented 2 years ago

When tailor is run for a terraform workspace, only the code is captured by the default.

We use pants' support for terraform just to track changes in our terraform monorepo. Because lock files are not captured, lockfile-only changes will not show up in our CI runs.

Pants version 2.9.0

OS Mac & linux

ryanking commented 2 years ago

To make this work, i manually updated my BUILD files to:

terraform_module(dependencies=[".terraform.lock.hcl"])
file(name="lock",source=".terraform.lock.hcl")
kaos commented 2 years ago

I guess you meant:

terraform_module(dependencies=[":lock"])
file(name="lock",source=".terraform.lock.hcl")
ryanking commented 2 years ago

Yeah just came here to correct that. Posted before I tested. :)

tdyas commented 2 years ago

The lock file could be added as an additional glob for the sources field on terraform_module. https://github.com/pantsbuild/pants/blob/a42dd729e9fbdc79e95116bef5e7e722be32ec04/src/python/pants/backend/terraform/target_types.py#L19

lilatomic commented 1 month ago

We implemented Terraform lockfile functionality in #20303 , but it uses magic to grab the lockfile directly instead of having a target for it. Because there's no real target, it won't show up in --changed-since. The Python backend generates targets for its lockfiles with a synthetic target. I think that could work here. One difference is that Python pulls the list of resolves from PythonSetup, but Terraform pulls it by enumerating modules.

kaos commented 1 month ago

Using synthetic targets could work, as long as they don't need data about other targets when being generated. i.e. if enumerating modules is about files on disk, rather than discovering targets?