Hey everyone, I'm exploring Pants as a potential t...
# plugins
f
Hey everyone, I'm exploring Pants as a potential tool to manage our codebase. I'm currently evaluating the plugin feature, because we will need this for our own custom tooling. There's quite a learning curve but I'm starting to get it. I'm currently trying to add a new linter (TFLint for Terraform) as an exercise. I am able to download and run the linter on my terraform modules. I achieved that by following how other linters (tfsec) were doing it. I'm now stuck at the following though: I need to add the dependencies of the module that I'm linting to the Digest in order for the linter to perform all checks. There is an infer_terraform_module_dependencies rule that I probably can use for this, but I don't understand how to get the current target and put it into the InferTerraformModuleDependenciesRequest. Here's the (WIP) plugin I am writing https://github.com/agoblet/polyglot-pants-example/tree/main/pants-plugins/tflint Do you know of any other plugins that do something similar? I can then have a look at that and try to copy the logic.
s
Hi! In pants linter is usually a tool that checks each file individually. If you need your linter to analyze other files to lint one, it's better to use
check
goal. For example, mypy type checker works this way, you can find the code in pants github repo
f
awesome, thanks for the clarification and the super quick response @square-psychiatrist-19087. Mypy indeed sounds like a good example to look at, since it also has to look at the relationship between files. Gonna take a look 🙂
f
also it seems like the Terraform backend already gathers transitive dependencies
see usages of the
TerraformInitRequest
and
TerraformInitResponse
types
f
thanks @fast-nail-55400 then probably I have to combine the
check
goal with some of the code already present in the
TerraformInitRequest
.
c
Do you need just all terraform files referenced, or also modules initialised and providers downloaded? TerraformInitRequest.sources_and_deps should have everything that
terraform init
would do. the tfsec linter was added before we had the machinery to pull in everything. You can look at how the
check
or
experimental-deploy
goals are implemented in TF, since those use an initialised terraform instance.
f
@careful-address-89803 I ended up using
check
indeed and got things working 🙂
👍 1