atlantis icon indicating copy to clipboard operation
atlantis copied to clipboard

Autoplanning - auto-detect modules dependencies

Open yannh opened this issue 5 years ago • 6 comments

Hello! In the autoplanning documentation, when configuring planning, you need to specify a when_modified array of folders to watch for each project.

This can be quite cumbersome to maintain, especially when you have modules that depend on other modules that depend on other modules.... I just released https://github.com/contentful-labs/terraform-diff, which uses https://github.com/hashicorp/terraform-config-inspect/ to try to detect the dependency tree automatically. Do you think this behaviour would work with Atlantis' autoplanning feature? It might be a bit of work but would you accept a PR going into that direction? Thanks!

yannh avatar Jan 31 '20 10:01 yannh

Yeah that would be awesome. We're already using terraform-config-inspect to determine the terraform version: https://github.com/runatlantis/atlantis/blob/master/server/events/project_command_builder.go#L433. Extending it to detect module changes would be great.

I'd need to think about how best to enable this functionality. Maybe we'd support another key under autoplan called module_autodetect: true or something. I wouldn't worry about that at first though, if you get the functionality working we can worry about config later.

lkysow avatar Feb 03 '20 17:02 lkysow

Hi, we have this issue with our teams, either we add a dependency to a module that we later don't need anymore but forgot to remove it from atlantis.yaml our we forget to mark one module as a dependency and Atlantis does not run when it should.

The only issue I see with it is that it would need to parse all Terraform files on every pull request but this should be short enough.

@yannh do you have a working patch for this? If not, I could try to add it, my plan is to recursively look for modules with a local path.

If it works fast enough, I think we should enable this feature by default, everybody must have this issue.

remilapeyre avatar Feb 17 '20 19:02 remilapeyre

Hi @remilapeyre , not yet. I can see it working when you have a configuration file specifying the list of projects to watch (so, patching DetermineProjectsViaConfig ).. I would probably work on this in the coming weeks but I can't commit to a timeline, so feel free to work on it!

yannh avatar Feb 17 '20 21:02 yannh

Reviving this ticket...

Seems like terraform-diff does exactly what is needed: output list of changed projects, but integrating it is still TODO? Anyone have a proof of concept or WIP? I'd be interested in getting it over the finish line.

iamnoah avatar Sep 07 '22 20:09 iamnoah

you can run any tool in a custom workflow so this could be added without issues, bit not need to be embedded in atlantis code I think

jamengual avatar Sep 07 '22 23:09 jamengual

@jamengual I would expect a workflow per directory output by the diff. e.g., if a module affects 5 projects, that's 5 different plans and applys.

iamnoah avatar Sep 08 '22 13:09 iamnoah