Skip to content
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

Incorrect backend config path causes crash #25822

Closed
alanplatt opened this issue Aug 12, 2020 · 4 comments
Closed

Incorrect backend config path causes crash #25822

alanplatt opened this issue Aug 12, 2020 · 4 comments
Labels
bug confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code v0.13 Issues (primarily bugs) reported against v0.13 releases

Comments

@alanplatt
Copy link

alanplatt commented Aug 12, 2020

Terraform Version

v0.13.0

Terraform Configuration Files

terraform {
  required_providers {
    google = {
      version = "~> 3.33.0"
    }
    kubernetes = {
      version = "~> 1.12.0"
    }
    random = {
      version = "~> 2.3.0"
    }
  }
}

Debug Output

▶ TF_LOG=trace terraform init --backend-config="tier/locals/backend.tfvars"                                                                                                (⎈ v2-verify:aptest)
2020/08/12 15:41:08 [INFO] Terraform version: 0.13.0  
2020/08/12 15:41:08 [INFO] Go runtime version: go1.14.2
2020/08/12 15:41:08 [INFO] CLI args: []string{"/usr/local/Cellar/tfenv/2.0.0/versions/0.13.0/terraform", "init", "--backend-config=tier/locals/backend.tfvars"}
2020/08/12 15:41:08 [DEBUG] Attempting to open CLI config file: /Users/alanplatt/.terraformrc
2020/08/12 15:41:08 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/08/12 15:41:08 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2020/08/12 15:41:08 [DEBUG] ignoring non-existing provider search directory /Users/alanplatt/.terraform.d/plugins
2020/08/12 15:41:08 [DEBUG] ignoring non-existing provider search directory /Users/alanplatt/Library/Application Support/io.terraform/plugins
2020/08/12 15:41:08 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2020/08/12 15:41:08 [INFO] CLI command args: []string{"init", "--backend-config=tier/locals/backend.tfvars"}
Initializing modules...
2020/08/12 15:41:08 [TRACE] ModuleInstaller: installing child modules for . into .terraform/modules
2020/08/12 15:41:08 [DEBUG] Module installer: begin jubilee-house
2020/08/12 15:41:08 [TRACE] ModuleInstaller: Module installer: jubilee-house <nil> already installed in modules/datacentre-certs
2020/08/12 15:41:08 [DEBUG] Module installer: begin woking
2020/08/12 15:41:08 [TRACE] ModuleInstaller: Module installer: woking <nil> already installed in modules/datacentre-certs
2020/08/12 15:41:08 [TRACE] modsdir: writing modules manifest to .terraform/modules/modules.json

Initializing the backend...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x2bfc425]

goroutine 1 [running]:
github.com/hashicorp/terraform/command.(*InitCommand).backendConfigOverrideBody(0xc00067e700, 0x32d6888, 0xf, 0xc000592380, 0xc000687d10, 0xc00059cff0, 0x29, 0x0, 0x0, 0x17762fa700000000)
        /home/circleci/project/project/command/init.go:862 +0x8b5
github.com/hashicorp/terraform/command.(*InitCommand).initBackend(0xc00067e700, 0xc0004537a0, 0x32d6888, 0xf, 0xc000592380, 0x1, 0x0, 0x0, 0x0, 0xc0000b9750, ...)
        /home/circleci/project/project/command/init.go:374 +0x4a6
github.com/hashicorp/terraform/command.(*InitCommand).Run(0xc00067e700, 0xc00004c1d0, 0x1, 0x1, 0xc0006440d0)
        /home/circleci/project/project/command/init.go:227 +0xeb1
github.com/mitchellh/cli.(*CLI).Run(0xc000652280, 0xc000652280, 0xc00063fd48, 0x1)
        /home/circleci/project/project/vendor/github.com/mitchellh/cli/cli.go:255 +0x1da
main.wrappedMain(0x0)
        /home/circleci/project/project/main.go:275 +0xc90
main.realMain(0x0)
        /home/circleci/project/project/main.go:106 +0xde
main.main()
        /home/circleci/project/project/main.go:42 +0x3a
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x2bfc425]

goroutine 1 [running]:
github.com/hashicorp/terraform/command.(*InitCommand).backendConfigOverrideBody(0xc00067e700, 0x32d6888, 0xf, 0xc000592380, 0xc000687d10, 0xc00059cff0, 0x29, 0x0, 0x0, 0x17762fa700000000)
        /home/circleci/project/project/command/init.go:862 +0x8b5
github.com/hashicorp/terraform/command.(*InitCommand).initBackend(0xc00067e700, 0xc0004537a0, 0x32d6888, 0xf, 0xc000592380, 0x1, 0x0, 0x0, 0x0, 0xc0000b9750, ...)
        /home/circleci/project/project/command/init.go:374 +0x4a6
github.com/hashicorp/terraform/command.(*InitCommand).Run(0xc00067e700, 0xc00004c1d0, 0x1, 0x1, 0xc0006440d0)
        /home/circleci/project/project/command/init.go:227 +0xeb1
github.com/mitchellh/cli.(*CLI).Run(0xc000652280, 0xc000652280, 0xc00063fd48, 0x1)
        /home/circleci/project/project/vendor/github.com/mitchellh/cli/cli.go:255 +0x1da
main.wrappedMain(0x0)
        /home/circleci/project/project/main.go:275 +0xc90
main.realMain(0x0)
        /home/circleci/project/project/main.go:106 +0xde
main.main()
        /home/circleci/project/project/main.go:42 +0x3a



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

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version. That
information is available on the first line of crash.log. You can also
get it by running 'terraform --version' on the command line.

SECURITY WARNING: the "crash.log" file that was created may contain 
sensitive information that must be redacted before it is safe to share 
on the issue tracker.

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

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

Crash Output

▶ cat crash.log                                                                                                                                                            (⎈ v2-verify:aptest)
2020/08/12 15:41:08 [INFO] Terraform version: 0.13.0  
2020/08/12 15:41:08 [INFO] Go runtime version: go1.14.2
2020/08/12 15:41:08 [INFO] CLI args: []string{"/usr/local/Cellar/tfenv/2.0.0/versions/0.13.0/terraform", "init", "--backend-config=tier/locals/backend.tfvars"}
2020/08/12 15:41:08 [DEBUG] Attempting to open CLI config file: /Users/alanplatt/.terraformrc
2020/08/12 15:41:08 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/08/12 15:41:08 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2020/08/12 15:41:08 [DEBUG] ignoring non-existing provider search directory /Users/alanplatt/.terraform.d/plugins
2020/08/12 15:41:08 [DEBUG] ignoring non-existing provider search directory /Users/alanplatt/Library/Application Support/io.terraform/plugins
2020/08/12 15:41:08 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2020/08/12 15:41:08 [INFO] CLI command args: []string{"init", "--backend-config=tier/locals/backend.tfvars"}
2020/08/12 15:41:08 [TRACE] ModuleInstaller: installing child modules for . into .terraform/modules
2020/08/12 15:41:08 [DEBUG] Module installer: begin jubilee-house
2020/08/12 15:41:08 [TRACE] ModuleInstaller: Module installer: jubilee-house <nil> already installed in modules/datacentre-certs
2020/08/12 15:41:08 [DEBUG] Module installer: begin woking
2020/08/12 15:41:08 [TRACE] ModuleInstaller: Module installer: woking <nil> already installed in modules/datacentre-certs
2020/08/12 15:41:08 [TRACE] modsdir: writing modules manifest to .terraform/modules/modules.json
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x2bfc425]

goroutine 1 [running]:
github.com/hashicorp/terraform/command.(*InitCommand).backendConfigOverrideBody(0xc00067e700, 0x32d6888, 0xf, 0xc000592380, 0xc000687d10, 0xc00059cff0, 0x29, 0x0, 0x0, 0x17762fa700000000)
        /home/circleci/project/project/command/init.go:862 +0x8b5
github.com/hashicorp/terraform/command.(*InitCommand).initBackend(0xc00067e700, 0xc0004537a0, 0x32d6888, 0xf, 0xc000592380, 0x1, 0x0, 0x0, 0x0, 0xc0000b9750, ...)
        /home/circleci/project/project/command/init.go:374 +0x4a6
github.com/hashicorp/terraform/command.(*InitCommand).Run(0xc00067e700, 0xc00004c1d0, 0x1, 0x1, 0xc0006440d0)
        /home/circleci/project/project/command/init.go:227 +0xeb1
github.com/mitchellh/cli.(*CLI).Run(0xc000652280, 0xc000652280, 0xc00063fd48, 0x1)
        /home/circleci/project/project/vendor/github.com/mitchellh/cli/cli.go:255 +0x1da
main.wrappedMain(0x0)
        /home/circleci/project/project/main.go:275 +0xc90
main.realMain(0x0)
        /home/circleci/project/project/main.go:106 +0xde
main.main()
        /home/circleci/project/project/main.go:42 +0x3a

Expected Behavior

When i pass the backend config, if the file path is incorrect it should say 'file not found'

Actual Behavior

terraform crashed

Steps to Reproduce

File path does not exists:

  1. `terraform init --backend-config="tier/locals/backend.tfvars"
@alanplatt alanplatt added bug new new issue not yet triaged labels Aug 12, 2020
@danieldreier
Copy link
Contributor

Hi @alanplatt! Thanks for reporting this! I was able to reproduce it. I created a trivial github reproduction case at https://github.com/danieldreier/terraform-issue-reproductions/tree/master/25822 to show it. When I ran yours as stated without a backend block in the HCL, it didn't crash, but it crashes just as you describe with a local backend configured.

@danieldreier danieldreier added confirmed a Terraform Core team member has reproduced this issue v0.13 Issues (primarily bugs) reported against v0.13 releases and removed new new issue not yet triaged labels Aug 12, 2020
@mildwonkey
Copy link
Contributor

There is an open PR that will fix this, #25804! I've already confirmed that PR fixes this issue. This is technically a breaking change, as previously users could specify a non-extant file as a shorthand for "empty out the backend config", so it should wait for 0.14.

If we wanted to fix the panic in 0.13 without breaking the current function, we could modify init to check if the file exists first, and if not treat that as an empty backend config file, around these lines:

terraform/command/init.go

Lines 857 to 858 in f5c8ef1

newBody, fileDiags := c.loadHCLFile(item.Value)
diags = diags.Append(fileDiags)

@mildwonkey mildwonkey added the explained a Terraform Core team member has described the root cause of this issue in code label Aug 14, 2020
@mildwonkey
Copy link
Contributor

This was merged for v0.13.1, so I am going to close this issue - thanks, and sorry again!

@ghost
Copy link

ghost commented Oct 11, 2020

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.

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Oct 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code v0.13 Issues (primarily bugs) reported against v0.13 releases
Projects
None yet
Development

No branches or pull requests

3 participants