This request is a follow-up to #15613, which was closed after versioning was added for module registry modules.
It would be extremely useful to use semver constraints on modules across our terraform codebase:
module "foo" {
source = "github.com/hashicorp/example"
version = "^0.1.1"
}
This would save users from widespread source code updates just to pick up patch fixes.
Would love this feature.
@jgiles does a single version work today, e.g.
module "foo" {
source = "github.com/hashicorp/example"
version = "0.1.1"
}
?
Or would that need to be done via ref somehow? e.g.
module "foo" {
source = "github.com/hashicorp/example?ref=0.1.1"
}
Also looking forward to something like this, though I'd personally prefer interpolation for the entire source parameter rather than just separating the version/ref.
We're successfully using the ref + release functionality with Github sources today, it just seems a little kludgy that it works one way for Terraform registry and another way for Github, when they're both effectively providing similar functionality.
@rarkins I believe you need to do the ref= thing currently, it's what we do all over the place.
We actually have a hacky mechanism where all our TF repo release tags are like v1.2.3-repo where in place of repo we put a short version of the repo name. This is purely to facilitate simpler find/replace of the tagged versions.
@jgiles thanks for the follow-up details. I added Terraform version upgrading to Renovate Bot just a couple of days ago actually, using the logic to look for semver-like ref tags like you mention. It would also work with your "hack" tags with one small config change, however an automated approach would save you from manual search/replace so you could do away with the hack instead if you preferred.
any chance to see this in future releases?
I guess there is conflict of interest with Terraform Enterprise's private module registry, which is paid product.
Looks like Terraform 0.12 broke the git ref trick for module versioning, so it would be really nice to either have it back or it actually implementing what's proposed here.
The ref argument is still functional in 0.12, though we saw in another issue that the behavior of the upstream library we use for non-registry sources seems to have subtly changed in how it understands the //subdir syntax.
If you were using something like git::ssh://example.com/bar.git?ref=foo//subdir with the intent of selecting the subdir directory within the repository, the correct way to write that is with the subdirectory part on the _path_ portion of the URL, like this:
git::ssh://example.com/bar.git//subdir?ref=foo
If you place it on the end, Terraform understands it instead as an attempt to use a branch called foo//subdir.
If the above doesn't explain a change in behavior you've seen, please open a new issue for it... there were no other changes intended here, so if there have been other regressions then we'll get them fixed up, but best to keep bug reports separate from feature requests so that we can track and prioritize them better.
@apparentlymart that was exactly the issue I was facing and I thought it was something related to specifying a ref, but it was indeed the path syntax. Thanks!
Any chance we can get this feature? So that we can use the expressions (>=, ~> etc.) that come out of the box to manage our SemVer tags.
Most helpful comment
Any chance we can get this feature? So that we can use the expressions (
>=,~>etc.) that come out of the box to manage our SemVer tags.