hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.72k stars 9.55k forks source link

GitHub module source truncates branch name after slash #34771

Closed brettcurtis closed 3 months ago

brettcurtis commented 8 months ago

Terraform Version

Terraform v1.7.4
on linux_amd64

Terraform Configuration Files

module "kubernetes" {
  source = "github.com/osinfra-io/terraform-google-kubernetes-engine?ref=brettcurtis/issue17"

  istio_gateway_ssl = var.istio_gateway_ssl
  project_id        = module.project.project_id
}

Debug Output

Error: Failed to download module
│ 
│   on main.tf line 96:
│   96: module "kubernetes" {
│ 
│ Could not download module "kubernetes" (main.tf:96) source code from
│ "git::https://github.com/osinfra-io/terraform-google-kubernetes-engine.git?ref=brettcurtis":
│ error downloading
│ 'https://github.com/osinfra-io/terraform-google-kubernetes-engine.git?ref=brettcurtis':
│ /usr/bin/git exited with 1: error: pathspec 'brettcurtis' did not match any
│ file(s) known to git

Expected Behavior

I'd expect the code to initialize.

Actual Behavior

It seems to truncate the name of my branch following the slash.

Steps to Reproduce

  1. terraform init

Additional Context

No response

References

No response

jbardin commented 8 months ago

Hi @brettcurtis,

Thanks for filing the issue. The branch specifier in this syntax is part of the URL query parameters, and the / is one of the reserved characters within a URI query component. This means that it must appear encoded as %2F to be parsed correctly.

The following module config initializes successfully:

module "kubernetes" {
  source = "github.com/osinfra-io/terraform-google-kubernetes-engine?ref=brettcurtis%2Fissue17"

  istio_gateway_ssl = var.istio_gateway_ssl
  project_id        = module.project.project_id
}
brettcurtis commented 8 months ago

Ok thanks bud! I could have sworn this worked fine for me in the past so i figured it was a bug.

ashwin1596 commented 3 months ago

Hi,

I am interested in working on this issue, update the documentation and believe it will help me learn more about the codebase.

Could you please confirm if I can start working on it?

Thank you!

crw commented 3 months ago

Hi @ashwin1596, thanks for offering to update the docs. Anyone can suggest changes to the docs, so feel free to do so. If this was going to be documented, I suppose it would be here: https://developer.hashicorp.com/terraform/language/modules/sources#github -- maybe just a note about making sure the URL is valid? It isn't really Terraform-specific guidance, just how to properly format URLs.

I would also suggest reading https://github.com/hashicorp/terraform/blob/main/.github/CONTRIBUTING.md. Thanks!

brettcurtis commented 3 months ago

Howdy, at the time of this issue I was pointing out that I thought this use to work so it felt buggy. Today in terraform 1.9.2 it works again...

crw commented 3 months ago

That is curious, I wonder what changed. I will raise this in triage to see if we know why the behavior may have changed.

crw commented 3 months ago

Linking this with https://github.com/hashicorp/go-getter/issues/479 per request of @jbardin.

jbardin commented 3 months ago

Thanks @crw, looking more closely that is related only to a gitlab issue parsed within go-getter. I'm going to close this with the dupe #34554.

github-actions[bot] commented 2 months ago

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. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.