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

hashicorp/hil panic when file() used without quotes #5672

Closed matthughes closed 8 years ago

matthughes commented 8 years ago

Terraform was running fine; now crashes on every command.

terraform version
Terraform v0.6.12

2016/03/16 17:40:08 [INFO] Terraform version: 0.6.12  
2016/03/16 17:40:08 [DEBUG] Detected home directory from env var: /Users/mhughes
2016/03/16 17:40:08 [DEBUG] Discovered plugin: atlas = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-atlas
2016/03/16 17:40:08 [DEBUG] Discovered plugin: aws = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-aws
2016/03/16 17:40:08 [DEBUG] Discovered plugin: azure = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-azure
2016/03/16 17:40:08 [DEBUG] Discovered plugin: azurerm = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-azurerm
2016/03/16 17:40:08 [DEBUG] Discovered plugin: chef = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-chef
2016/03/16 17:40:08 [DEBUG] Discovered plugin: cloudflare = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-cloudflare
2016/03/16 17:40:08 [DEBUG] Discovered plugin: cloudstack = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-cloudstack
2016/03/16 17:40:08 [DEBUG] Discovered plugin: consul = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-consul
2016/03/16 17:40:08 [DEBUG] Discovered plugin: datadog = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-datadog
2016/03/16 17:40:08 [DEBUG] Discovered plugin: digitalocean = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-digitalocean
2016/03/16 17:40:08 [DEBUG] Discovered plugin: dme = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-dme
2016/03/16 17:40:08 [DEBUG] Discovered plugin: dnsimple = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-dnsimple
2016/03/16 17:40:08 [DEBUG] Discovered plugin: docker = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-docker
2016/03/16 17:40:08 [DEBUG] Discovered plugin: dyn = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-dyn
2016/03/16 17:40:08 [DEBUG] Discovered plugin: google = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-google
2016/03/16 17:40:08 [DEBUG] Discovered plugin: heroku = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-heroku
2016/03/16 17:40:08 [DEBUG] Discovered plugin: mailgun = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-mailgun
2016/03/16 17:40:08 [DEBUG] Discovered plugin: mysql = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-mysql
2016/03/16 17:40:08 [DEBUG] Discovered plugin: null = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-null
2016/03/16 17:40:08 [DEBUG] Discovered plugin: openstack = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-openstack
2016/03/16 17:40:08 [DEBUG] Discovered plugin: packet = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-packet
2016/03/16 17:40:08 [DEBUG] Discovered plugin: postgresql = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-postgresql
2016/03/16 17:40:08 [DEBUG] Discovered plugin: powerdns = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-powerdns
2016/03/16 17:40:08 [DEBUG] Discovered plugin: rundeck = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-rundeck
2016/03/16 17:40:08 [DEBUG] Discovered plugin: statuscake = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-statuscake
2016/03/16 17:40:08 [DEBUG] Discovered plugin: template = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-template
2016/03/16 17:40:08 [DEBUG] Discovered plugin: terraform = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-terraform
2016/03/16 17:40:08 [DEBUG] Discovered plugin: tls = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-tls
2016/03/16 17:40:08 [DEBUG] Discovered plugin: vcd = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-vcd
2016/03/16 17:40:08 [DEBUG] Discovered plugin: vsphere = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provider-vsphere
2016/03/16 17:40:08 [DEBUG] Discovered plugin: chef = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provisioner-chef
2016/03/16 17:40:08 [DEBUG] Discovered plugin: file = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provisioner-file
2016/03/16 17:40:08 [DEBUG] Discovered plugin: local-exec = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provisioner-local-exec
2016/03/16 17:40:08 [DEBUG] Discovered plugin: remote-exec = /usr/local/Cellar/terraform/0.6.12/bin/terraform-provisioner-remote-exec
2016/03/16 17:40:08 [DEBUG] Detected home directory from env var: /Users/mhughes
2016/03/16 17:40:08 [DEBUG] Attempting to open CLI config file: /Users/mhughes/.terraformrc
2016/03/16 17:40:08 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2016/03/16 17:40:08 [DEBUG] Detected home directory from env var: /Users/mhughes
2016/03/16 17:40:08 [DEBUG] waiting for all plugin processes to complete...
panic: Unary - is only allowed

goroutine 1 [running]:
panic(0x820340, 0xc8203f65a0)
    /usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.(*parserParserImpl).Parse(0xc8204ca088, 0x135a9d8, 0xc820362420, 0x0)
    lang.y:132 +0x2202
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.parserParse(0x135a9d8, 0xc820362420, 0x1150d30)
    yaccpar:154 +0x49
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.Parse(0xc820300480, 0x2e, 0x0, 0x0, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/parse.go:27 +0x103
github.com/hashicorp/terraform/config.(*interpolationWalker).Primitive(0xc8200fa160, 0x820340, 0xc8203f63d0, 0x98, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/interpolate_walk.go:116 +0x155
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walkPrimitive(0x810a00, 0xc8203f6440, 0x94, 0xb154a0, 0xc8200fa160, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:186 +0xa9
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walk(0x820340, 0xc8203f63d0, 0x98, 0xb154a0, 0xc8200fa160, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:117 +0x312
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walkMap(0x81bbc0, 0xc820300450, 0x15, 0xb154a0, 0xc8200fa160, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:168 +0x599
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walk(0x81bbc0, 0xc820300450, 0x15, 0xb154a0, 0xc8200fa160, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:120 +0x42c
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.Walk(0x81bbc0, 0xc820300450, 0xb154a0, 0xc8200fa160, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:70 +0x14c
github.com/hashicorp/terraform/config.(*RawConfig).init(0xc8203622a0, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/raw_config.go:216 +0x11a
github.com/hashicorp/terraform/config.NewRawConfig(0xc820300450, 0xc8204ca070, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/raw_config.go:44 +0x76
github.com/hashicorp/terraform/config.loadProvisionersHcl(0xc8204c2240, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/loader_hcl.go:637 +0x704
github.com/hashicorp/terraform/config.loadResourcesHcl(0xc820262b40, 0x0, 0x0, 0x0, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/loader_hcl.go:516 +0x1db5
github.com/hashicorp/terraform/config.(*hclConfigurable).Config(0xc820262a00, 0xb7ca90, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/loader_hcl.go:118 +0xd66
github.com/hashicorp/terraform/config.(*importTree).ConfigTree(0xc820270240, 0x5b, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/import_tree.go:87 +0x68
github.com/hashicorp/terraform/config.LoadFile(0xc820018f00, 0x5b, 0x0, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/loader.go:44 +0x80
github.com/hashicorp/terraform/config.LoadDir(0xc820018004, 0x4e, 0x0, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/loader.go:91 +0x38c
github.com/hashicorp/terraform/config/module.NewTreeModule(0x0, 0x0, 0xc820018004, 0x4e, 0x0, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/config/module/tree.go:40 +0x41
github.com/hashicorp/terraform/command.(*Meta).Context(0xc8201dc0f0, 0xc820018004, 0x4e, 0xc4e930, 0x11, 0x0, 0x0, 0x4, 0xb3c7d0, 0x0, ...)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/command/meta.go:148 +0x509
github.com/hashicorp/terraform/command.(*RefreshCommand).Run(0xc8201dc0f0, 0xc82000a350, 0x0, 0x0, 0xc8200148b0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/command/refresh.go:85 +0xb02
github.com/hashicorp/terraform/vendor/github.com/mitchellh/cli.(*CLI).Run(0xc8201d60c0, 0xc82001b110, 0x0, 0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/cli/cli.go:153 +0x5ee
main.wrappedMain(0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/main.go:140 +0xb05
main.realMain(0x0)
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/main.go:76 +0xa10
main.main()
    /private/tmp/terraform20160227-37732-w3ykp1/terraform-0.6.12/src/github.com/hashicorp/terraform/main.go:19 +0x18
matthughes commented 8 years ago

Apparently using file without quotes is what blew it up:

  provisioner "file" {
      source = "foo"
      destination = "bar"
      connection {
        user = "core"
        agent = false
        private_key = "${file(/Users/mhughes/my_key.pem)}"
      }
  }
phinze commented 8 years ago

Thanks for the report, @matthughes, and sorry for the confusing error condition here! We'll get this fixed up soon.

phinze commented 8 years ago

Minimal repro config:

resource "aws_instance" "foo" {
  ami = "${file(/tmp/somefile)}"
}
wallies commented 8 years ago

I recently got this exact same crash.log, on the same version of terraform. Here is my resource.

resource "template_file" "etcd_discovery_url" {
  template = "${file(/dev/null)}"
  provisioner "local-exec" {
    command = "curl https://discovery.etcd.io/new?size=${var.masters} > ${var.etcd_discovery_url_file}"
  }
  # This will regenerate the discovery URL if the cluster size changes
  vars {
    size = "${var.masters}"
  }
}
mitchellh commented 8 years ago

Have a fix queued up, just need to update deps once it is merged.

ghost commented 4 years 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.