IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
341 stars 670 forks source link

TF/Golang panic when previous deployment had an error #212

Closed FrenchBen closed 6 years ago

FrenchBen commented 6 years ago

After a previous deployment had an error, the following terraform refresh (during apply) will trigger a golang panic.

Terraform Version

Terraform v0.11.6

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "ibm_compute_vm_instance" "vm_instances" {
  count = "2"
  ....
}

resource "ibm_lbaas" "lbaas" {
  name        = "terraformLB"
  description = "delete this"
  subnets     = [1511875]

  protocols = [{
    frontend_protocol     = "HTTPS"
    frontend_port         = 443
    backend_protocol      = "HTTP"
    backend_port          = 80
    load_balancing_method = "round_robin"
    tls_certificate_id    = 11670
  },
    {
      frontend_protocol     = "HTTP"
      frontend_port         = 80
      backend_protocol      = "HTTP"
      backend_port          = 80
      load_balancing_method = "round_robin"
    },
{
      frontend_protocol     = "HTTP"
      frontend_port         = 8080
      backend_protocol      = "HTTP"
      backend_port          = 8080
      load_balancing_method = "round_robin"
    },
  ]

  server_instances = [
    {
      "private_ip_address" = "${ibm_compute_vm_instance.vm_instances.0.ipv4_address_private}"
    },
    {
      "private_ip_address" = "${ibm_compute_vm_instance.vm_instances.1.ipv4_address_private}"
    },
  ]
}

Debug Output

The above will trigger a 500 error:

Error during creation of Load balancer: SoftLayer_Exception_InvalidValue: Invalid value provided for 'protocolConfigurations'. The provided number of Protocol Configurations (3) exceeds the allowed maximum of 2. (HTTP 500)

Remove the extra 8080 entry and run terraform apply or terraform refresh - Notice the panic

Panic Output

panic: runtime error: index out of range

goroutine 3122 [running]:
github.com/hashicorp/terraform/config.interpolationFuncFormatList.func1(0xc420219740, 0x4, 0x4, 0xc420219740, 0x4, 0x4, 0x100000040)
    /opt/gopath/src/github.com/hashicorp/terraform/config/interpolate_funcs.go:677 +0x81d
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.(*evalCall).Eval(0xc420aecfa8, 0x2b83920, 0xc42042e480, 0xc420218dd0, 0x0, 0x0, 0xc420966bd8, 0x9db3fe, 0xc420218dd0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/eval.go:283 +0x2ce
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.(*evalVisitor).visit(0xc420218dc0, 0x2b8d5a0, 0xc42065fe50, 0x2b8d6e0, 0xc4200c1bf0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/eval.go:215 +0xf6
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.(*evalVisitor).(github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.visit)-fm(0x2b8d5a0, 0xc42065fe50, 0x2b8d6e0, 0xc4200c1bf0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/eval.go:175 +0x3e
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/ast.(*Call).Accept(0xc42065fe50, 0xc42042fe80, 0x2b8d660, 0xc420218400)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/ast/call.go:20 +0xe5
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/ast.(*Call).Accept(0xc42065fea0, 0xc42042fe80, 0x2b8d5a0, 0xc42065ff90)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/ast/call.go:17 +0x73
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/ast.(*Conditional).Accept(0xc42065fef0, 0xc42042fe80, 0x4106c8, 0x10)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/ast/conditional.go:18 +0x85
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/ast.(*Output).Accept(0xc420218cc0, 0xc42042fe80, 0xc4205d9000, 0xc42065ff80)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/ast/output.go:20 +0x72
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.(*evalVisitor).Visit(0xc420218dc0, 0x2b8d6a0, 0xc420218cc0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/eval.go:175 +0xa2
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.internalEval(0x2b8d6a0, 0xc420218cc0, 0xc420420cc0, 0x9d8d8f, 0xc4200903c0, 0x2b8d6a0, 0xc420218cc0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/eval.go:153 +0x6e7
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.Eval(0x2b8d6a0, 0xc420218cc0, 0xc420420cc0, 0x0, 0x2b8d6a0, 0xc420218cc0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/eval.go:52 +0x49
github.com/hashicorp/terraform/config.(*RawConfig).Interpolate.func1(0x2b8d6a0, 0xc420218cc0, 0x2b8d6a0, 0xc420218cc0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/config/raw_config.go:178 +0x42
github.com/hashicorp/terraform/config.(*interpolationWalker).Primitive(0xc42039a3c0, 0x22feee0, 0xc42042fcc0, 0x94, 0xc42039a3c0, 0xc4200c5b01)
    /opt/gopath/src/github.com/hashicorp/terraform/config/interpolate_walk.go:147 +0x145
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walkPrimitive(0x22feee0, 0xc42042fcc0, 0x94, 0x279a5c0, 0xc42039a3c0, 0x98, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:251 +0x80
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walk(0x22feee0, 0xc42042fcc0, 0x94, 0x279a5c0, 0xc42039a3c0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:179 +0x1ff
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walkMap(0x23558a0, 0xc420343800, 0x195, 0x279a5c0, 0xc42039a3c0, 0x40ce00, 0xc42002e000)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:233 +0x2f1
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walk(0x23558a0, 0xc420343800, 0x195, 0x279a5c0, 0xc42039a3c0, 0x1, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:182 +0x3ef
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walkSlice(0x202ba00, 0xc420420d80, 0x97, 0x279a5c0, 0xc42039a3c0, 0x97, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:283 +0x20d
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walk(0x22feee0, 0xc42042ece0, 0x94, 0x279a5c0, 0xc42039a3c0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:185 +0x35c
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walkMap(0x23558a0, 0xc4200c0960, 0x15, 0x279a5c0, 0xc42039a3c0, 0x40ce00, 0xc42002e000)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:233 +0x2f1
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.walk(0x23558a0, 0xc4200c0960, 0x15, 0x279a5c0, 0xc42039a3c0, 0x1, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:182 +0x3ef
github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk.Walk(0x23558a0, 0xc4200c0960, 0x279a5c0, 0xc42039a3c0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go:92 +0x131
github.com/hashicorp/terraform/config.(*RawConfig).interpolate(0xc4209eabd0, 0xc42042e490, 0xc4209eac18, 0x1030100)
    /opt/gopath/src/github.com/hashicorp/terraform/config/raw_config.go:286 +0x14d
github.com/hashicorp/terraform/config.(*RawConfig).Interpolate(0xc4209eabd0, 0xc4200c0780, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/config/raw_config.go:175 +0xcd
github.com/hashicorp/terraform/terraform.(*BuiltinEvalContext).Interpolate(0xc4201fba00, 0xc4209eabd0, 0xc42041e460, 0xc420967838, 0x4d5620, 0xc4200a20f0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_context_builtin.go:249 +0xef
github.com/hashicorp/terraform/terraform.(*EvalInterpolate).Eval(0xc420467a00, 0x2ba0f00, 0xc4201fba00, 0x2, 0x2, 0xc420514840, 0xe)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_interpolate.go:19 +0x4e
github.com/hashicorp/terraform/terraform.EvalRaw(0x2b7be20, 0xc420467a00, 0x2ba0f00, 0xc4201fba00, 0x279a940, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:53 +0x156
github.com/hashicorp/terraform/terraform.(*EvalSequence).Eval(0xc420467a80, 0x2ba0f00, 0xc4201fba00, 0x2, 0x2, 0xc420514820, 0xe)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_sequence.go:14 +0x7a
github.com/hashicorp/terraform/terraform.EvalRaw(0x2b7bfc0, 0xc420467a80, 0x2ba0f00, 0xc4201fba00, 0x22fcfc0, 0x44cce45, 0x2075d00, 0xc4200c52d0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:53 +0x156
github.com/hashicorp/terraform/terraform.Eval(0x2b7bfc0, 0xc420467a80, 0x2ba0f00, 0xc4201fba00, 0xc420467a80, 0x2b7bfc0, 0xc420467a80, 0xc42023c6e0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:34 +0x4d
github.com/hashicorp/terraform/terraform.(*Graph).walk.func1(0x28c49c0, 0xc420aec2c8, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/graph.go:126 +0xc26
github.com/hashicorp/terraform/dag.(*Walker).walkVertex(0xc4209eab60, 0x28c49c0, 0xc420aec2c8, 0xc420983a80)
    /opt/gopath/src/github.com/hashicorp/terraform/dag/walk.go:387 +0x3a0
created by github.com/hashicorp/terraform/dag.(*Walker).Update
    /opt/gopath/src/github.com/hashicorp/terraform/dag/walk.go:310 +0x1248

Expected Behavior

TF not to panic and for the apply/refresh to work

Actual Behavior

TF panics and you can no longer do anything

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. Fix the tf template to have only 2 entries for the LB
  3. terraform apply
Praveengostu commented 6 years ago

@FrenchBen From terraform we will try to remove the limitation of adding protocols during creation. Will let you know once the fix is available.

Praveengostu commented 6 years ago

@FrenchBen The fix is available in the latest build located at https://github.com/IBM-Cloud/terraform-provider-ibm/releases/tag/v0.9.1