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.78k stars 9.56k forks source link

Panic when module source is a malformed S3 address #35515

Closed liamg closed 3 months ago

liamg commented 3 months ago

Terraform Version

Tried v1.6.0 and v1.9.3

Terraform Configuration Files

module "uhoh" {
  source = "s3.amazonaws.com/bucket"
}

Debug Output

2024-07-30T16:17:24.344Z [INFO]  Terraform version: 1.9.3
2024-07-30T16:17:24.344Z [DEBUG] using github.com/hashicorp/go-tfe v1.51.0
2024-07-30T16:17:24.344Z [DEBUG] using github.com/hashicorp/hcl/v2 v2.20.0
2024-07-30T16:17:24.344Z [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2024-07-30T16:17:24.344Z [DEBUG] using github.com/zclconf/go-cty v1.14.4
2024-07-30T16:17:24.344Z [INFO]  Go runtime version: go1.22.5
2024-07-30T16:17:24.344Z [INFO]  CLI args: []string{"/bin/terraform", "init"}
2024-07-30T16:17:24.344Z [TRACE] Stdout is a terminal of width 98
2024-07-30T16:17:24.344Z [TRACE] Stderr is a terminal of width 98
2024-07-30T16:17:24.344Z [TRACE] Stdin is a terminal
2024-07-30T16:17:24.344Z [DEBUG] Attempting to open CLI config file: /root/.terraformrc
2024-07-30T16:17:24.344Z [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2024-07-30T16:17:24.344Z [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2024-07-30T16:17:24.344Z [DEBUG] ignoring non-existing provider search directory /root/.terraform.d/plugins
2024-07-30T16:17:24.345Z [DEBUG] ignoring non-existing provider search directory /root/.local/share/terraform/plugins
2024-07-30T16:17:24.345Z [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2024-07-30T16:17:24.345Z [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2024-07-30T16:17:24.346Z [INFO]  CLI command args: []string{"init"}
Initializing the backend...
2024-07-30T16:17:24.348Z [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2024-07-30T16:17:24.348Z [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2024-07-30T16:17:24.348Z [TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
2024-07-30T16:17:24.348Z [TRACE] Meta.Backend: instantiated backend of type <nil>
2024-07-30T16:17:24.348Z [DEBUG] checking for provisioner in "."
2024-07-30T16:17:24.349Z [DEBUG] checking for provisioner in "/bin"
2024-07-30T16:17:24.349Z [TRACE] Meta.Backend: backend <nil> does not support operations, so wrapping it in a local backend
2024-07-30T16:17:24.349Z [TRACE] backend/local: state manager for workspace "default" will:
 - read initial snapshot from terraform.tfstate
 - write new snapshots to terraform.tfstate
 - create any backup at terraform.tfstate.backup
2024-07-30T16:17:24.349Z [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
2024-07-30T16:17:24.349Z [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
2024-07-30T16:17:24.349Z [TRACE] statemgr.Filesystem: read nil snapshot
Initializing modules...
2024-07-30T16:17:24.349Z [TRACE] ModuleInstaller: installing child modules for . into .terraform/modules
2024-07-30T16:17:24.350Z [DEBUG] Module installer: begin uhoh
2024-07-30T16:17:24.350Z [TRACE] ModuleInstaller: uhoh is not yet installed
2024-07-30T16:17:24.350Z [TRACE] ModuleInstaller: cleaning directory .terraform/modules/uhoh prior to install of uhoh
2024-07-30T16:17:24.350Z [TRACE] ModuleInstaller: uhoh address "s3::https://s3.amazonaws.com/bucket" will be handled by go-getter
Downloading s3::https://s3.amazonaws.com/bucket for uhoh...
2024-07-30T16:17:24.350Z [TRACE] getmodules: fetching "s3::https://s3.amazonaws.com/bucket" to ".terraform/modules/uhoh"

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

panic: runtime error: index out of range [2] with length 2
goroutine 1 [running]:
runtime/debug.Stack()
    runtime/debug/stack.go:24 +0x64
github.com/hashicorp/terraform/internal/logging.PanicHandler()
    github.com/hashicorp/terraform/internal/logging/panic.go:84 +0x198
panic({0x2b8af80?, 0x4000074e40?})
    runtime/panic.go:770 +0x124
github.com/hashicorp/go-getter.(*S3Getter).parseUrl(0x28?, 0x400028db00)
    github.com/hashicorp/go-getter@v1.7.5/get_s3.go:272 +0x7e0
github.com/hashicorp/go-getter.(*S3Getter).Get(0x400097c360, {0x4000074d80, 0x17}, 0x400028db00)
    github.com/hashicorp/go-getter@v1.7.5/get_s3.go:90 +0xc4
github.com/hashicorp/go-getter.(*Client).Get(0x4000af8160)
    github.com/hashicorp/go-getter@v1.7.5/client.go:321 +0xae0
github.com/hashicorp/terraform/internal/getmodules.reusingGetter.getWithGoGetter(0x400098dc20, {0x3684458, 0x400098d4a0}, {0x4000074d80, 0x17}, {0x4000896330, 0x23})
    github.com/hashicorp/terraform/internal/getmodules/getter.go:137 +0x3c4
github.com/hashicorp/terraform/internal/getmodules.(*PackageFetcher).FetchPackage(...)
    github.com/hashicorp/terraform/internal/getmodules/installer.go:46
github.com/hashicorp/terraform/internal/initwd.(*ModuleInstaller).installGoGetterModule(0x400098d5c0, {0x3684458, 0x400098d4a0}, 0x400094f320, {0x40008ec168, 0x4}, {0x4000074d80, 0x17}, 0x400098dbf0, {0x365a640, ...}, ...)
    github.com/hashicorp/terraform/internal/initwd/module_install.go:712 +0x2ac
github.com/hashicorp/terraform/internal/initwd.(*ModuleInstaller).InstallModules.(*ModuleInstaller).moduleInstallWalker.func2(0x400094f320)
    github.com/hashicorp/terraform/internal/initwd/module_install.go:282 +0x8e0
github.com/hashicorp/terraform/internal/configs.ModuleWalkerFunc.LoadModule(0x4000b1eba8?, 0x7df98?)
    github.com/hashicorp/terraform/internal/configs/config_build.go:280 +0x28
github.com/hashicorp/terraform/internal/configs.loadModule(0x400080c7e0, 0x400094f320, {0x3649c40, 0x40008ce2d0})
    github.com/hashicorp/terraform/internal/configs/config_build.go:191 +0x3c
github.com/hashicorp/terraform/internal/configs.buildChildModules(0x400080c7e0, {0x3649c40, 0x40008ce2d0})
    github.com/hashicorp/terraform/internal/configs/config_build.go:174 +0x3b8
github.com/hashicorp/terraform/internal/configs.BuildConfig(0x40004ec5a0, {0x3649c40, 0x40008ce2d0}, {0x3649c80, 0x400097c580})
    github.com/hashicorp/terraform/internal/configs/config_build.go:33 +0x74
github.com/hashicorp/terraform/internal/initwd.(*ModuleInstaller).installDescendentModules(0x400098d5c0, 0x40004ec5a0, 0x400098dbf0, {0x3649c40, 0x40008ce2d0}, 0x0)
    github.com/hashicorp/terraform/internal/initwd/module_install.go:315 +0x114
github.com/hashicorp/terraform/internal/initwd.(*ModuleInstaller).InstallModules(0x400098d5c0, {0x3684458, 0x400098d4a0}, {0x3636c98, 0x1}, {0x2d92183, 0x5}, 0x0, 0x0, {0x365a640, ...})
    github.com/hashicorp/terraform/internal/initwd/module_install.go:140 +0x4c4
github.com/hashicorp/terraform/internal/command.(*Meta).installModules(0x4000ac2380, {0x3684458?, 0x400098d440?}, {0x4000ad6018, 0x11}, {0x2d92183, 0x5}, 0x0, 0x0, {0x365a640, ...})
    github.com/hashicorp/terraform/internal/command/meta_config.go:206 +0x2f4
github.com/hashicorp/terraform/internal/command.(*InitCommand).getModules(0x4000ac2380, {0x3684490, 0x4000af2050}, {0x4000ad6018, 0x11}, {0x2d92183, 0x5}, 0x40004ec1e0, 0x0, {0x3689960, ...})
    github.com/hashicorp/terraform/internal/command/init.go:368 +0x410
github.com/hashicorp/terraform/internal/command.(*InitCommand).Run(0x4000ac2380, {0x400006e050?, 0x0?, 0x0?})
    github.com/hashicorp/terraform/internal/command/init.go:226 +0xea8
github.com/hashicorp/cli.(*CLI).Run(0x4000adc000)
    github.com/hashicorp/cli@v1.1.6/cli.go:265 +0x4a8
main.realMain()
    github.com/hashicorp/terraform/main.go:339 +0x18f8
main.main()
    github.com/hashicorp/terraform/main.go:64 +0x1c

Expected Behavior

No panic

Actual Behavior

Panic

Steps to Reproduce

  1. terraform init with the above example

Additional Context

Fix in go-getter below.

References

https://github.com/hashicorp/go-getter/pull/501

crw commented 3 months ago

Thanks for this report and the potential fix!

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.