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

conditional in array is returning a panic error #11342

Closed
rolele opened this issue Jan 22, 2017 · 6 comments
Closed

conditional in array is returning a panic error #11342

rolele opened this issue Jan 22, 2017 · 6 comments

Comments

@rolele
Copy link

rolele commented Jan 22, 2017

I have this terraform script that is meant to create 3 machine: managers.[0-2] and a block storage

I would like the block storage to be attached to the first manager only

    resource "digitalocean_volume" "myvol-01" {
        region      = "sfo2"
        name        = "myvol-01"
        size        = 1
        description = "an example volume"
    }

    resource "digitalocean_droplet" "managers" {
      count = "${var.managers_size}"
      name = "managers.${count.index}"
      ssh_keys = ["${var.ssh_fingerprint}"]
      region = "sfo2"
      image = "centos-7-x64"
      size = "512mb"
      #### volume_ids = ["${digitalocean_volume.myvol-01.id}"]
    }

I do not know how to conditionally attached the volume only to the first machine.
I tried
volume_ids = "${count.index == 0 ? ["${digitalocean_volume.myvol-01.id}"] : false }"
OR this did not work neither:
volume_ids = ["${count.index == 0 ? "${digitalocean_volume.myvol-01.id}" : ""}"]

someone proposed this:
volume_ids = ["${count.index == 0 ? digitalocean_volume.myvol-01.id : ""}"]

but this is returning a panic error

terraform apply                                                                                                                                                                9:44
digitalocean_volume.myvol-01: Refreshing state... (ID: 3857c233-e06d-11e6-9b24-000f533132d0)
digitalocean_volume.myvol-01: Creating...
  description:   "" => "an example volume"
  droplet_ids.#: "" => "<computed>"
  name:          "" => "myvol-01"
  region:        "" => "sfo2"
  size:          "" => "1"
digitalocean_volume.myvol-01: Creation complete
digitalocean_droplet.managers.0: Creating...
  disk:                 "" => "<computed>"
  image:                "" => "centos-7-x64"
  ipv4_address:         "" => "<computed>"
  ipv4_address_private: "" => "<computed>"
  ipv6_address:         "" => "<computed>"
  ipv6_address_private: "" => "<computed>"
  locked:               "" => "<computed>"
  name:                 "" => "managers.0"
  region:               "" => "sfo2"
  resize_disk:          "" => "true"
  size:                 "" => "512mb"
  ssh_keys.#:           "" => "1"
  ssh_keys.0:           "" => "06:61:3d:44:c7:30:64:d4:32:be:f6:e3:4a:65:c7:6c"
  status:               "" => "<computed>"
  vcpus:                "" => "<computed>"
  volume_ids.#:         "" => "1"
  volume_ids.0:         "" => "6c4dbd2c-e0f4-11e6-a17e-000f5339e930"
digitalocean_droplet.managers.1: Creating...
  disk:                 "" => "<computed>"
  image:                "" => "centos-7-x64"
  ipv4_address:         "" => "<computed>"
  ipv4_address_private: "" => "<computed>"
  ipv6_address:         "" => "<computed>"
  ipv6_address_private: "" => "<computed>"
  locked:               "" => "<computed>"
  name:                 "" => "managers.1"
  region:               "" => "sfo2"
  resize_disk:          "" => "true"
  size:                 "" => "512mb"
  ssh_keys.#:           "" => "1"
  ssh_keys.0:           "" => "06:61:3d:44:c7:30:64:d4:32:be:f6:e3:4a:65:c7:6c"
  status:               "" => "<computed>"
  vcpus:                "" => "<computed>"
  volume_ids.#:         "" => "1"
digitalocean_droplet.managers.2: Creating...
  disk:                 "" => "<computed>"
  image:                "" => "centos-7-x64"
  ipv4_address:         "" => "<computed>"
  ipv4_address_private: "" => "<computed>"
  ipv6_address:         "" => "<computed>"
  ipv6_address_private: "" => "<computed>"
  locked:               "" => "<computed>"
  name:                 "" => "managers.2"
  region:               "" => "sfo2"
  resize_disk:          "" => "true"
  size:                 "" => "512mb"
  ssh_keys.#:           "" => "1"
  ssh_keys.0:           "" => "06:61:3d:44:c7:30:64:d4:32:be:f6:e3:4a:65:c7:6c"
  status:               "" => "<computed>"
  vcpus:                "" => "<computed>"
  volume_ids.#:         "" => "1"
Error applying plan:

3 error(s) occurred:

* digitalocean_droplet.managers.2: unexpected EOF
* digitalocean_droplet.managers.1: unexpected EOF
* digitalocean_droplet.managers.0: unexpected EOF

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
panic: interface conversion: interface is nil, not string
2017/01/23 09:45:10 [DEBUG] plugin: terraform:
2017/01/23 09:45:10 [DEBUG] plugin: terraform: goroutine 129 [running]:
2017/01/23 09:45:10 [DEBUG] plugin: terraform: panic(0x2ddf660, 0x4265ba100)
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.7.4/libexec/src/runtime/panic.go:500 +0x1a1
2017/01/23 09:45:10 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/builtin/providers/digitalocean.resourceDigitalOceanDropletCreate(0x426454840, 0x2e45b80, 0x4263e2280, 0x4263d04b0, 0x16444)
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /private/tmp/terraform-20161214-2441-3cw6bz/terraform-0.8.0/src/github.com/hashicorp/terraform/builtin/providers/digitalocean/resource_digitalocean_droplet.go:179 +0xe56
2017/01/23 09:45:10 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0x4262aa7e0, 0x42641e0a0, 0x4265ae200, 0x2e45b80, 0x4263e2280, 0x1, 0x4261da000, 0x18)
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /private/tmp/terraform-20161214-2441-3cw6bz/terraform-0.8.0/src/github.com/hashicorp/terraform/helper/schema/resource.go:162 +0x30e
2017/01/23 09:45:10 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0x4262aaea0, 0x42641e050, 0x42641e0a0, 0x4265ae200, 0x0, 0x4263d4cf8, 0x18c9b)
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /private/tmp/terraform-20161214-2441-3cw6bz/terraform-0.8.0/src/github.com/hashicorp/terraform/helper/schema/provider.go:212 +0x9b
2017/01/23 09:45:10 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Apply(0x4265a54c0, 0x4265ae120, 0x4264602d0, 0x0, 0x0)
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /private/tmp/terraform-20161214-2441-3cw6bz/terraform-0.8.0/src/github.com/hashicorp/terraform/plugin/resource_provider.go:488 +0x57
2017/01/23 09:45:10 [DEBUG] plugin: terraform: reflect.Value.call(0x4262aa6c0, 0x425fe1158, 0x13, 0x3445850, 0x4, 0x4266cdee0, 0x3, 0x3, 0x2, 0x4263d4b30, ...)
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.7.4/libexec/src/reflect/value.go:434 +0x5c8
2017/01/23 09:45:10 [DEBUG] plugin: terraform: reflect.Value.Call(0x4262aa6c0, 0x425fe1158, 0x13, 0x4266cdee0, 0x3, 0x3, 0x0, 0x425fdb780, 0xb4b670)
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.7.4/libexec/src/reflect/value.go:302 +0xa4
2017/01/23 09:45:10 [DEBUG] plugin: terraform: net/rpc.(*service).call(0x42644efc0, 0x42644ef80, 0x4262d5f60, 0x426632880, 0x4265a5660, 0x29aa980, 0x4265ae120, 0x16, 0x29aa9c0, 0x4264602d0, ...)
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.7.4/libexec/src/net/rpc/server.go:383 +0x148
2017/01/23 09:45:10 [DEBUG] plugin: terraform: created by net/rpc.(*Server).ServeCodec
2017/01/23 09:45:10 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.7.4/libexec/src/net/rpc/server.go:477 +0x421
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* digitalocean_droplet.managers.2: unexpected EOF
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* digitalocean_droplet.managers.2: unexpected EOF
2017/01/23 09:45:10 [TRACE] [walkApply] Exiting eval tree: digitalocean_droplet.managers[2]
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* digitalocean_droplet.managers.1: unexpected EOF
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* digitalocean_droplet.managers.1: unexpected EOF
2017/01/23 09:45:10 [DEBUG] plugin: /usr/local/Cellar/terraform/0.8.0/bin/terraform: plugin process exited
2017/01/23 09:45:10 [TRACE] [walkApply] Exiting eval tree: digitalocean_droplet.managers[1]
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* digitalocean_droplet.managers.0: unexpected EOF
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred

* digitalocean_droplet.managers.0: unexpected EOF
2017/01/23 09:45:10 [TRACE] [walkApply] Exiting eval tree: digitalocean_droplet.managers[0]
2017/01/23 09:45:10 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "digitalocean_droplet.managers[0]"
2017/01/23 09:45:10 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "digitalocean_droplet.managers[2]"
2017/01/23 09:45:10 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "digitalocean_droplet.managers[1]"
2017/01/23 09:45:10 [INFO] Starting shadow graph walk: walkApply
2017/01/23 09:45:10 [DEBUG] Waiting for shadow graph to complete...
2017/01/23 09:45:10 [DEBUG] vertex 'root.var.digitalocean_token': walking
2017/01/23 09:45:10 [DEBUG] vertex 'root.var.workers_size': walking
2017/01/23 09:45:10 [DEBUG] vertex "provider.digitalocean", got dep: "var.digitalocean_token"
2017/01/23 09:45:10 [DEBUG] vertex 'root.var.digitalocean_ssh_key': walking
2017/01/23 09:45:10 [DEBUG] vertex 'root.provider.digitalocean': walking
2017/01/23 09:45:10 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.workers_size"
2017/01/23 09:45:10 [DEBUG] vertex 'root.var.managers_size': walking
2017/01/23 09:45:10 [DEBUG] vertex 'root.var.ssh_fingerprint': walking
2017/01/23 09:45:10 [DEBUG] vertex 'root.provider.digitalocean': evaluating
2017/01/23 09:45:10 [TRACE] [walkApply] Entering eval tree: provider.digitalocean
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalSequence
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInitProvider
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[1]", got dep: "var.managers_size"
2017/01/23 09:45:10 [DEBUG] root: eval: terraform.EvalNoop
2017/01/23 09:45:10 [DEBUG] root: eval: terraform.EvalNoop
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalSequence
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[1]", got dep: "var.ssh_fingerprint"
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[2]", got dep: "var.managers_size"
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalBuildProviderConfig
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalSetProviderConfig
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalSequence
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalConfigProvider
2017/01/23 09:45:10 [TRACE] [walkApply] Exiting eval tree: provider.digitalocean
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_volume.myvol-01", got dep: "provider.digitalocean"
2017/01/23 09:45:10 [DEBUG] vertex 'root.digitalocean_volume.myvol-01': walking
2017/01/23 09:45:10 [DEBUG] vertex 'root.digitalocean_volume.myvol-01': evaluating
2017/01/23 09:45:10 [TRACE] [walkApply] Entering eval tree: digitalocean_volume.myvol-01
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalSequence
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInstanceInfo
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: terraform.EvalNoop
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalValidateResource
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalCompareDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApply
2017/01/23 09:45:10 [DEBUG] apply: digitalocean_volume.myvol-01: executing Apply
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalUpdateStateHook
2017/01/23 09:45:10 [TRACE] [walkApply] Exiting eval tree: digitalocean_volume.myvol-01
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[0]", got dep: "digitalocean_volume.myvol-01"
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[0]", got dep: "var.managers_size"
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[2]", got dep: "digitalocean_volume.myvol-01"
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[1]", got dep: "digitalocean_volume.myvol-01"
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[2]", got dep: "var.ssh_fingerprint"
2017/01/23 09:45:10 [DEBUG] vertex 'root.digitalocean_droplet.managers[1]': walking
2017/01/23 09:45:10 [DEBUG] vertex 'root.digitalocean_droplet.managers[2]': walking
2017/01/23 09:45:10 [DEBUG] vertex "digitalocean_droplet.managers[0]", got dep: "var.ssh_fingerprint"
2017/01/23 09:45:10 [DEBUG] vertex 'root.digitalocean_droplet.managers[0]': walking
2017/01/23 09:45:10 [DEBUG] vertex 'root.digitalocean_droplet.managers[1]': evaluating
2017/01/23 09:45:10 [TRACE] [walkApply] Entering eval tree: digitalocean_droplet.managers[1]
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalSequence
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInstanceInfo
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: terraform.EvalNoop
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/01/23 09:45:10 [DEBUG] vertex 'root.digitalocean_droplet.managers[2]': evaluating
2017/01/23 09:45:10 [TRACE] [walkApply] Entering eval tree: digitalocean_droplet.managers[2]
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalSequence
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInstanceInfo
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: terraform.EvalNoop
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalValidateResource
2017/01/23 09:45:10 [DEBUG] vertex 'root.digitalocean_droplet.managers[0]': evaluating
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalDiff
2017/01/23 09:45:10 [TRACE] [walkApply] Entering eval tree: digitalocean_droplet.managers[0]
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalSequence
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInstanceInfo
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: terraform.EvalNoop
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalCompareDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalValidateResource
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalCompareDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalValidateResource
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApply
2017/01/23 09:45:10 [DEBUG] apply: digitalocean_droplet.managers.1: executing Apply
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApply
2017/01/23 09:45:10 [DEBUG] apply: digitalocean_droplet.managers.2: executing Apply
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalCompareDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* digitalocean_droplet.managers.1: unexpected EOF
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* digitalocean_droplet.managers.1: unexpected EOF
2017/01/23 09:45:10 [TRACE] [walkApply] Exiting eval tree: digitalocean_droplet.managers[1]
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* digitalocean_droplet.managers.2: unexpected EOF
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* digitalocean_droplet.managers.2: unexpected EOF
2017/01/23 09:45:10 [TRACE] [walkApply] Exiting eval tree: digitalocean_droplet.managers[2]
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalReadState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApply
2017/01/23 09:45:10 [DEBUG] apply: digitalocean_droplet.managers.0: executing Apply
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalIf
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteState
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/01/23 09:45:10 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* digitalocean_droplet.managers.0: unexpected EOF
2017/01/23 09:45:10 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* digitalocean_droplet.managers.0: unexpected EOF
2017/01/23 09:45:10 [TRACE] [walkApply] Exiting eval tree: digitalocean_droplet.managers[0]
2017/01/23 09:45:10 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "digitalocean_droplet.managers[0]"
2017/01/23 09:45:10 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "digitalocean_droplet.managers[2]"
2017/01/23 09:45:10 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "digitalocean_droplet.managers[1]"
2017/01/23 09:45:10 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.digitalocean_ssh_key"
2017/01/23 09:45:10 [ERROR] Shadow graph error: 3 error(s) occurred:
@rolele
Copy link
Author

rolele commented Jan 23, 2017

I tried this but no luck

variable "optional" {
  default = ""
}

  volume_ids = ["${count.index==0 ? digitalocean_volume.myvol-01.id : compact(split(",", var.optional)) }"]
Error creating plan: 3 error(s) occurred:                                                             │
                                                                                                      │
* At column 3, line 1: true and false expression types must match; have type string and type list in: │
                                                                                                      │
${count.index==0 ? digitalocean_volume.myvol-01.id : compact(split(",", var.optional)) }              │
* At column 3, line 1: true and false expression types must match; have type string and type list in: │
                                                                                                      │
${count.index==0 ? digitalocean_volume.myvol-01.id : compact(split(",", var.optional)) }              │
* At column 3, line 1: true and false expression types must match; have type string and type list in: │
                                                                                                      │
${count.index==0 ? digitalocean_volume.myvol-01.id : compact(split(",", var.optional)) }

also doing this does not work neither

volume_ids = "${count.index==0 ? compact(split(",", digitalocean_volume.myvol-01.id)) : compact(split(",", var.optional)) }"

Error creating plan: 3 error(s) occurred:

* At column 3, line 1: conditional operator cannot be used with list values in:

${count.index==0 ? compact(split(",", digitalocean_volume.myvol-01.id)) : compact(split(",", var.optional)) }
* At column 3, line 1: conditional operator cannot be used with list values in:

${count.index==0 ? compact(split(",", digitalocean_volume.myvol-01.id)) : compact(split(",", var.optional)) }
* At column 3, line 1: conditional operator cannot be used with list values in:

${count.index==0 ? compact(split(",", digitalocean_volume.myvol-01.id)) : compact(split(",", var.optional)) }

@rolele
Copy link
Author

rolele commented Jan 24, 2017

While messing around I tried using those values alone and I could to build 1 machine with a volume attached

#attach volume
volume_ids = ["${compact(split(",", digitalocean_volume.myvol-01.id))}”] 
#do not crash and do not attach anything
volume_ids = [ "${compact(split(",", var.optional))}”] 

but seeing that "conditional operator cannot be used with list values"
I tried another approach using null_resource

variable "optional" {
 default = ""
}

resource "null_resource" "add_volume" {
 vars {
   count_index = "${count.index}"
 }
 count = "${null_resource.add_volume.count_index}"
 template = "${compact(split(",", digitalocean_volume.myvol-01.id))}"
}

resource "null_resource" "do_not_add_volume" {
 vars {
   count_index = "${count.index}"
 }
 count = "${1 - null_resource.do_not_add_volume.count_index}"
 template = "${compact(split(",", var.optional))}"
}

resource "digitalocean_droplet" "managers" {
 count = "${var.managers_size}"
 name = "managers.${count.index}"
 ssh_keys = ["${var.ssh_fingerprint}"]
 region = "sfo2"
 image = "centos-7-x64"
 size = "512mb"
 volume_ids = ["${element(concat(element(null_resource.add_volume.rendered, count.index), element(null_resource.do_not_add_volume.rendered, count.index)), 0)}"]
}

but in that case I have trouble passing count.index from the digitalocean_droplet resource to the null_resource.
I am getting an error saying null_resource.add_volume.count_index could not be found.
I am not even sure this is a good approach

@jsalbright
Copy link

jsalbright commented May 5, 2017

I came across a similar problem this morning regarding dynamic lists based on conditional syntax. The proposed solution was to use the list() function:

resource "azurerm_virtual_machine" "jenkins_vm" {
  name                  = "jenkinsVM"
  location              = "${var.jenkins_location}"
  vm_size               = "${var.jenkins_vm_size}"
  resource_group_name   = "${azurerm_resource_group.jenkins_rg.name}"
  network_interface_ids	= ["${var.dry_run == "false" ? list(azurerm_network_interface.jenkins_nic.id) : list(azurerm_network_interface.jenkins_nic.id, azurerm_network_interface.jenkins_nic_test.id)}"]
}

Unfortunately, I still continue to get the same exact error about using conditionals in a list attribute that was claimed to have been fixed in March's release..

Tested using Terraform 0.9.3.

Please reply with an update. Conditional values in list attributes was claimed to have been implemented/fixed in March's release, but continues to be unsupported.

@radeksimko
Copy link
Member

This can be fixed in the provider codebase, so it doesn't crash, but generally speaking calling Get() on

volume_ids = ["${count.index == 0 ? digitalocean_volume.myvol-01.id : ""}"]

shouldn't ever produce []interface{}{nil} in any provider - so that's something to address in core, which is why I'm reopening this issue.

@radeksimko radeksimko reopened this Sep 14, 2017
@teamterraform
Copy link
Contributor

Prior to Terraform 0.12 there were some missing validation rules in the SDK that were causing these crashes. From 0.12 onwards, the type checking validations are handled by Terraform Core itself and so it's no longer possible to hit these crashing codepaths.

The parts of Terraform that deal with validation were changed significantly in Terraform 0.12, so if you see any similar problems with validation rules in Terraform 0.12.0 or later, please open a new issue so we can capture an updated set of debug information about the new situation. Because the codepath that was crashing here should no longer run in Terraform 0.12, we're going to close this now.

@ghost
Copy link

ghost commented Aug 17, 2019

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 Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants