-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
addrs.ModuleSource
string format doesn't properly handle subdirectories with query parameters
#31250
Comments
Hi @mkielar, Thanks for filing the issue. I don't think there's much we can do here to resolve the problem with IntelliJ, Terraform needs the values stored in the internal modules manifest structured the way they are for a number of reasons. Nothing within the Also, I think the fact that IntelliJ was able to use If the IntelliJ team wants to engage directly for advice, either with us or the Terraform Language Server team, they are more than welcome! Thanks |
Sorry @mkielar, I didn't quite realize that the format which seems to work with IntelliJ was what was being stored in the module manifest. That does seem to be an irregularity we'd like to resolve for consistency, so that nothing is tripped up by it in the future. Since the string stored in the manifest isn't something Terraform tries to reverse, it's not going to cause a problem with the normal init process. One thing to still consider here is that changing the string format will change the keys in the manifest, requiring existing working directories to re-init. This may not be a problem, but could be something to consider when making this change in a patch vs a minor release. Thanks again! |
addrs.ModuleSource
string format doesn't properly handle subdirectories with query parameters
I don't think modern Terraform actually makes use of that source address information saved in the hidden module manifest, since these days we use a directory name derived from the module call path instead, and the other information saved in the JSON is sufficient for that. So this information appears to be vestigial as far as Terraform is concerned and has apparently regressed at some point. However, I suspect this arose from the increased use of our address normalisation logic in more places, in an effort to give better feedback to the user about how Terraform is understanding the addresses, and so my suspicion is that this incorrect normalisation is probably also appearing in the UI in some cases, such as in the progress reports from Either way it does seem like a bug, since Terraform is producing a misleading normalized form that reinterprets the subdirectory path as a part of the ref argument, so we should fix that. I do want to note that this |
I had some time to play with this a little directly, rather than guessing from memory, and I just wanted to correct my previous statement a little: The So with that said, I think this problem is likely more isolated to the hidden module manifest cache than I previously asserted. We don't typically need to reproduce module source strings from the normalized in-memory form in typical processing, and so it might be that the manifest file is the only place that actually needs to do it in practice. Of course that doesn't mean we shouldn't still fix it, but it's a relief that the problem seems to be more isolated than I originally expected. |
Here's a reproduction case that uses a repository that's available publicly, just in case it's helpful to anyone working on this: module "consul_consul-client-security-group-rules" {
# (this is the git repository underneath the "hashicorp/consul/aws" registry module)
source = "git::https://github.com/hashicorp/terraform-aws-consul//modules/consul-client-security-group-rules?ref=v0.11.0"
} When I run
However, the {
"Modules": [
{
"Key": "",
"Source": "",
"Dir": "."
},
{
"Key": "consul_consul-client-security-group-rules",
"Source": "git::https://github.com/hashicorp/terraform-aws-consul?ref=v0.11.0//modules/consul-client-security-group-rules",
"Dir": ".terraform/modules/consul_consul-client-security-group-rules/modules/consul-client-security-group-rules"
}
]
} The "git::https://github.com/hashicorp/terraform-aws-consul//modules/consul-client-security-group-rules?ref=v0.11.0" |
It seems like the problem here is that the terraform/internal/addrs/module_source.go Lines 455 to 460 in 9db277a
This is effectively the same as the
|
Can I pick this up? Can you please point me to the changes required and the files I need to look at? |
Hi @deepto98! Thanks for the interest in working on this. My previous two comments here were my attempt to document the expected behavior and the area of code that seems to be the cause. If you have specific questions about those details, please let me know! |
Okay, thanks. I'll go through them. |
@apparentlymart I guess this can be closed due to #31636 |
Hi @fatahfattah! Indeed, I did forget to close this after merging your PR. I'm going to close it now. I merged your fix into the main branch so it should be included in the v1.4 release once we get there. We've only just started the v1.4 development period so it will be some time before it's available in a final release, but you should be able to see it in the 1.4.0 alpha releases once we start producing them (which typically happens only after there's something interesting in the main branch that we'd like early feedback on.) |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Git version
Terraform Configuration Files
terraform init
/terraform get
fail on fresh workspace.Debug Output
N/A / See "Actual Behavior"
Expected Behavior
Depending on the solution decided, I'd expect one of the following:
Source
values in.terraform/modules.json
should not get modified and should have the same values assource
attributes in HCL.terraform get
/terraform init
should be able to download modules using the URL syntax stored in.terraform/modules.json
/Source
fieldsActual Behavior
We have a private Git repository where we store a bunch of terraform modules for internal use. We then refer to them in HCL using
git::https://....
syntax, and use bothref
and/path/to/module
. We use IntelliJ IDEA with Terraform Plugin installed to work on this.We've noticed that the modules fetched by
terraform init
/terraform get
do not get autocomplete working in Terraform Plugin.Turns our this is because how
terraform
changes the URLs provided in thesource
when it stores module references in.terraform/modules.json
. In the case of the configuration presented above, the revelant section of the.terraform/modules.tf
looks like this (formatted for clarity):You can see how the
Source
in that JSON is not the same as thesource
in HCL - the?ref=master
section of the URL has been moved inside the URL. There are several issues with this:.terraform/modules.json
/Source
fields is not syntactically correct.To experiment with pt. 2, I modified the
source
attribute of the module in my HCL to match the.terraform/modules.json
/Source
field:When I did this, two things happened:
terraform init
/terraform get
immediatelly stopped working, throwing following errors:Looks like, when presented with an URL of its own making, Terraform is not able to fetch the module any more, because the
git
is unable to understand where theref
parameter is ending, and where thepath
in the repository begins.Steps to Reproduce
terraform get
.terraform/modules.json
and see the value inSource
for this module is different to the value ofsource
in your HCLsource
attribute in your HCL to the value ofSource
from.terraform/modules.json
.terraform
to forceterraform
to reinitialize workspaceterraform get
againterraform get
fails because Git doesn't understand the new URL.References
https://youtrack.jetbrains.com/issue/PY-49332
The text was updated successfully, but these errors were encountered: