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

crashed when resource does not exist #12788

Closed
vicfl opened this issue Mar 16, 2017 · 7 comments · Fixed by #12793
Closed

crashed when resource does not exist #12788

vicfl opened this issue Mar 16, 2017 · 7 comments · Fixed by #12793
Assignees

Comments

@vicfl
Copy link

vicfl commented Mar 16, 2017

Terraform Version

Terraform v0.9.0 (MacOs Sierra)

Affected Resource(s)

When you try to reference a resource which is actually generated by a module and does not exist you get this crashed, however under 0.8.6 you can get the exact details about which resource has not been created.

Panic Output

goroutine 432 [running]:
github.com/hashicorp/terraform/config/module.(*Tree).Validate(0xc42039b180, 0xc42042f170, 0x8)
	/opt/gopath/src/github.com/hashicorp/terraform/config/module/tree.go:358 +0xe65
github.com/hashicorp/terraform/terraform.(*Context).Validate(0xc420432360, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/context.go:644 +0xd0
github.com/hashicorp/terraform/backend/local.(*Local).context(0xc4200a70e0, 0xc4200b4630, 0x2, 0x2, 0x3, 0xc420130440, 0x2)
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend_local.go:82 +0x262
github.com/hashicorp/terraform/backend/local.(*Local).opPlan(0xc4200a70e0, 0x6ff44a0, 0xc420084260, 0xc4200b4630, 0xc4203abe30)
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend_plan.go:57 +0x22f
github.com/hashicorp/terraform/backend/local.(*Local).(github.com/hashicorp/terraform/backend/local.opPlan)-fm(0x6ff44a0, 0xc420084260, 0xc4200b4630, 0xc4203abe30)
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend.go:224 +0x52
github.com/hashicorp/terraform/backend/local.(*Local).Operation.func1(0xc4200a70e0, 0xc42042eba0, 0xc42042eb90, 0x6ff44a0, 0xc420084260, 0xc4200b4630, 0xc4203abe30)
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend.go:246 +0x9a
created by github.com/hashicorp/terraform/backend/local.(*Local).Operation
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend.go:247 +0x192

Expected Behavior

Terraform should tell you which resource does not exist (or give you a hint such as in 0.8.6)

Actual Behavior

Crashed

Steps to Reproduce

execute terraform plan

@mitchellh
Copy link
Contributor

Do you have a reproduction example we can run? Using your basic description of "reference a resource which is actually generated by a module and does not exist" I was unable to reproduce this. I'm probably just missing something. :)

@mitchellh mitchellh added the waiting-response An issue/pull request is waiting for a response from the community label Mar 17, 2017
@vicfl
Copy link
Author

vicfl commented Mar 17, 2017

Sure, sorry about that I can't use same code but I was able to reproduce this issue on this small example:

example1.tf

resource "aws_instance" "web" {
  ami           = "${data.aws_ami.ubuntu.id}"
  instance_type = "t2.micro"

  security_groups = ["${module.my_security_groups.my_sg.id}"]

  tags {
    Name = "HelloWorld"
  }
}

output

panic: module not found in children: my_security_groups

goroutine 420 [running]:
github.com/hashicorp/terraform/config/module.(*Tree).Validate(0xc420018960, 0xc4204010b0, 0x8)
	/opt/gopath/src/github.com/hashicorp/terraform/config/module/tree.go:358 +0xe65
github.com/hashicorp/terraform/terraform.(*Context).Validate(0xc4204826c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/context.go:644 +0xd0
github.com/hashicorp/terraform/backend/local.(*Local).context(0xc42008eb40, 0xc420151b80, 0x2, 0x2, 0x3, 0xc420474a80, 0x2)
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend_local.go:82 +0x262
github.com/hashicorp/terraform/backend/local.(*Local).opPlan(0xc42008eb40, 0x6ff44a0, 0xc420012560, 0xc420151b80, 0xc420479710)
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend_plan.go:57 +0x22f
github.com/hashicorp/terraform/backend/local.(*Local).(github.com/hashicorp/terraform/backend/local.opPlan)-fm(0x6ff44a0, 0xc420012560, 0xc420151b80, 0xc420479710)
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend.go:224 +0x52
github.com/hashicorp/terraform/backend/local.(*Local).Operation.func1(0xc42008eb40, 0xc420400ae0, 0xc420400ad0, 0x6ff44a0, 0xc420012560, 0xc420151b80, 0xc420479710)
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend.go:246 +0x9a
created by github.com/hashicorp/terraform/backend/local.(*Local).Operation
	/opt/gopath/src/github.com/hashicorp/terraform/backend/local/backend.go:247 +0x192

running terraform 0.8.6 you get this output:

Error loading Terraform: module root: 2 error(s) occurred:

* resource 'aws_instance.web' config: unknown module referenced: my_security_groups
* resource 'aws_instance.web' config: unknown resource 'data.aws_ami.ubuntu' referenced in variable data.aws_ami.ubuntu.id
make: *** [src/analytics/environments/main/cron] Error 1

@mitchellh
Copy link
Contributor

Got it reproduced. Thanks. Looks like our validation is failing when you reference a non-existent module!

@mitchellh mitchellh removed the waiting-response An issue/pull request is waiting for a response from the community label Mar 17, 2017
@mitchellh mitchellh self-assigned this Mar 17, 2017
@vicfl
Copy link
Author

vicfl commented Mar 17, 2017

no worries, sorry about my poor first description and I am glad you are able to reproduce it :). Just let me know if you need anything else.

mitchellh added a commit that referenced this issue Mar 17, 2017
Fixes #12788

We would panic when referencing an output from an undefined module. The
panic above this is correct but in this case Load will not catch
interpolated variables that _reference_ an unloaded/undefined module.
Test included.
@mitchellh
Copy link
Contributor

PR has the fix, will be released tomorrow.

@vicfl
Copy link
Author

vicfl commented Mar 17, 2017

Legend! thanks!

@ghost
Copy link

ghost commented Apr 15, 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.

@ghost ghost locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants