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

core: provider block inside resource causes crash on plan #5740

Closed
twashing opened this issue Mar 20, 2016 · 5 comments · Fixed by #5749
Closed

core: provider block inside resource causes crash on plan #5740

twashing opened this issue Mar 20, 2016 · 5 comments · Fixed by #5749

Comments

@twashing
Copy link

I've just downloaded and started playing around with Terraform. Creating a simple aws.tfconfig file, then running terraform plan, gave a _panic: runtime error: index out of range_ .

Here's the version.

$ terraform --version
Terraform v0.6.13

Here's the (probably erroneous) config file.

$ cat aws.tf 
resource "aws" "web" {
  provider = "aws" {
    region = "us-west-2"
  }
}

And here's the crash log

$  terraform plan
panic: runtime error: index out of range

goroutine 1 [running]:
panic(0xa03460, 0x82131c080)
    /opt/go/src/runtime/panic.go:464 +0x3e6
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl.(*decoder).decodeMap(0x82143ca58, 0xb8dda8, 0x4, 0x88213604c0, 0x82144bca0, 0x821480, 0x82133a1d0, 0x195, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl/decoder.go:330 +0x1363
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl.(*decoder).decode(0x82143ca58, 0xb8dda8, 0x4, 0x88213604f0, 0x821325560, 0x821480, 0x82133a1d0, 0x195, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl/decoder.go:89 +0x7f4
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl.DecodeObject(0x7ecc60, 0x82133a1d0, 0x88213604f0, 0x821325560, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl/decoder.go:49 +0x25f
github.com/hashicorp/terraform/config.loadResourcesHcl(0x82144be00, 0x0, 0x0, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/config/loader_hcl.go:441 +0x939
github.com/hashicorp/terraform/config.(*hclConfigurable).Config(0x82144bce0, 0xb85318, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/config/loader_hcl.go:118 +0xd66
github.com/hashicorp/terraform/config.(*importTree).ConfigTree(0x8214a6b00, 0x23, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/config/import_tree.go:87 +0x68
github.com/hashicorp/terraform/config.LoadFile(0x8214a0fc0, 0x23, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/config/loader.go:44 +0x80
github.com/hashicorp/terraform/config.LoadDir(0x821314124, 0x1c, 0x11, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/config/loader.go:91 +0x38c
github.com/hashicorp/terraform/config/module.NewTreeModule(0x0, 0x0, 0x821314124, 0x1c, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/config/module/tree.go:40 +0x41
github.com/hashicorp/terraform/command.(*Meta).Context(0x82149a0f0, 0x821314124, 0x1c, 0xc577e0, 0x11, 0x0, 0xa, 0x4, 0x7fff5fbff60e, 0x0, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/command/meta.go:148 +0x509
github.com/hashicorp/terraform/command.(*PlanCommand).Run(0x82149a0f0, 0x8213142b0, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/command/plan.go:66 +0x80d
github.com/hashicorp/terraform/vendor/github.com/mitchellh/cli.(*CLI).Run(0x8213c4600, 0x8214a0600, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/cli/cli.go:153 +0x5ee
main.wrappedMain(0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/main.go:140 +0xb05
main.realMain(0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/main.go:76 +0xa10
main.main()
    /opt/gopath/src/github.com/hashicorp/terraform/main.go:19 +0x18



!!!!!!!!!!!!!!!!!!!!!!!!!!! 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.

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

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
@radeksimko radeksimko changed the title Terraform v0.6.13, Panic / Crash on "terraform plan" core: provider block inside resource causes crash on plan Mar 21, 2016
@jen20
Copy link
Contributor

jen20 commented Mar 21, 2016

Hi @twashing! I can reproduce this - it's a bug in the the hcl library used to parse Terraform configuration. Thanks for reporting!

jen20 added a commit to hashicorp/hcl that referenced this issue Mar 21, 2016
This now gives an error instead of a panic when encountering
configuration such as described in hashicorp/terraform#5740:

```
resource "aws" "web" {
  provider = "aws" {
    region = "us-west-2"
  }
}
```

We now return an error message - "hcl object keys must be a string"
instead of crashing.

Fixes hashicorp/terraform#5740.
@jen20
Copy link
Contributor

jen20 commented Mar 21, 2016

This should be fixed by hashicorp/hcl#105 - once that has been reviewed and merged (likely later today when the US timezones come one) we can update the vendored version for a fix in 0.6.14.

As you say - this is invalid configuration (though that is no excuse for a crash!): what you probably want is:

provider = "aws" {
  region = "us-west-2"
}

resource "aws" "web" {
  // automatically attaches to provider
}

Thanks for reporting this!

jen20 added a commit to hashicorp/hcl that referenced this issue Mar 21, 2016
This now gives an error instead of a panic when encountering
configuration such as described in hashicorp/terraform#5740:

```
resource "aws" "web" {
  provider = "aws" {
    region = "us-west-2"
  }
}
```

We now return an error message - "hcl object keys must be a string"
instead of crashing.

Fixes hashicorp/terraform#5740.
jen20 added a commit to hashicorp/hcl that referenced this issue Mar 21, 2016
This now gives an error instead of a panic when encountering
configuration such as described in hashicorp/terraform#5740:

```
resource "aws" "web" {
  provider = "aws" {
    region = "us-west-2"
  }
}
```

We now return an error message - "hcl object keys must be a string"
instead of crashing.

Fixes hashicorp/terraform#5740.
@jen20 jen20 reopened this Mar 21, 2016
jen20 added a commit that referenced this issue Mar 21, 2016
@jen20
Copy link
Contributor

jen20 commented Mar 21, 2016

Closed this by mistake when the HCL fix got merged - it will actually be fixed in Terraform when #5749 lands.

@twashing
Copy link
Author

Thanks for addressign this Jen. Hope the report was helpful.

@ghost
Copy link

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

3 participants