tfvc icon indicating copy to clipboard operation
tfvc copied to clipboard

Feature request: Recursive mode

Open ktamas opened this issue 2 years ago • 8 comments

It'd be great to have a recursive mode, we have a monorepo with lots of modules.

ktamas avatar Oct 26 '22 11:10 ktamas

@KTamas I thought about this, but given that you can currently just pass multiple directories to tfvc I decided that was good enough for me at the moment. Does that not meet your requirement? e.g.

tfvc ./directory1 ./directory2 ./directory3

ryan-jan avatar Oct 26 '22 14:10 ryan-jan

The problem is that even that's not without issues, for example:

$ tfvc . modules/vpc

provider 'hashicorp/aws' WARNING Configured version does not match the latest available version
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  Resolution
  ──────────────────────────────────────────────────────────
  Consider using the latest version of this provider

  Details
  ────────────────────────────────────────────────────────
  Type:                provider
  Path:                .
  Name:                hashicorp/aws
  Source:              registry.terraform.io/hashicorp/aws
  Version Constraints: 4.29.0
  Version:             4.29.0
  Latest Match:
  Latest Overall:      4.36.1

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

module 'vpc' WARNING Configured version does not match the latest available version
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  Resolution
  ────────────────────────────────────────────────────────
  Consider using the latest version of this module

  Details
  ──────────────────────────────────────────────────
  Type:                module
  Path:                modules/vpc/main.tf
  Name:                vpc
  Source:              terraform-aws-modules/vpc/aws
  Version Constraints: 3.14.4
  Version:             3.14.4
  Latest Match:
  Latest Overall:      3.18.0

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────


terraform FAILED Missing version constraints
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  Resolution
  ───────────────────────────────────────────────────
  Configure version constraints for terraform

  Details
  ───────────────────────────────────────────────────
  Type:                terraform
  Path:                modules/vpc
  Name:                terraform
  Source:              github.com/hashicorp/terraform
  Version Constraints:
  Version:
  Latest Match:
  Latest Overall:      1.3.3

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  1. we have many many modules and listing them by hand is just, Not Great
  2. This error is misleading terraform FAILED Missing version constraints

ktamas avatar Oct 26 '22 14:10 ktamas

Ah, yes, point 2 is related to #34 however, I do understand your point 1. I will leave this open and take a look at it when I get a chance.

ryan-jan avatar Oct 26 '22 17:10 ryan-jan

@KTamas on further thought, I actually don't think your 2nd point above "This error is misleading terraform FAILED Missing version constraints" is quite correct. Your modules/vpc module should be defining a version constraint for the version(s) of terraform that it supports in a terraform { required_version = "x" } block. Does your vpc module have this configured?

ryan-jan avatar Oct 27 '22 06:10 ryan-jan

Ah, right, we don't have that. Mostly because it's a non-issue for us, most of the time. Perhaps an option to disable that check?

ktamas avatar Oct 27 '22 09:10 ktamas

Perhaps, I definitely want to add something to be able to ignore checks etc. just haven't looked at the best way to do it yet.

ryan-jan avatar Oct 27 '22 09:10 ryan-jan

Recursive mode would help us greatly as we're preparing a migration to AWS provider v4 across the board in our monorepo.

mihaiplesa avatar Nov 02 '22 13:11 mihaiplesa

I've been thinking about this a bit more and I'm still not sold on the idea. The issue is that it could end up adding a lot of complexity as I'm sure everyone will have different repo structures/requirements. For example, some people might only want to recurse one level deep, others might only want to recurse into a specific subdirectory called modules, others might want full multi-level recursion etc. etc.

My point is, currently you can specify multiple directories (separated by a comma) to tfvc and it will happily loop through them all. If that is not sufficient then it should be pretty trivial for people to put together a simple script to work out which directories they want to recurse into and just run tfvc in a for loop.

I'll leave this open for a bit longer in case people want to add some weight to the feature, but for now it is probably not going to implemented.

ryan-jan avatar Nov 05 '22 20:11 ryan-jan