linode / terraform-provider-linode

Terraform Linode provider
https://www.terraform.io/docs/providers/linode/
Mozilla Public License 2.0
202 stars 98 forks source link

linode_nodebalancer: `Error: missing expected [` #338

Closed Gurpartap closed 3 years ago

Gurpartap commented 3 years ago

Terraform Version

Terraform v0.15.5
on darwin_amd64

Effected Resource(s)

Terraform Configuration Files

resource "linode_nodebalancer" "loadbalancer1" {
  label  = "loadbalancer1"
  region = var.linode_dallas
}

resource "linode_nodebalancer_config" "loadbalancer1_internal" {
  nodebalancer_id = linode_nodebalancer.loadbalancer1.id

  port           = var.internal_frontend_port
  protocol       = "http"
  check          = "http"
  check_path     = "/haproxy/monitor"
  check_interval = 10
  check_timeout  = 3
  check_attempts = 2
  algorithm      = "roundrobin"
}

resource "linode_nodebalancer_node" "loadbalancer1_internal_backend" {
  count = length(linode_instance.workerpool1.*.id)

  nodebalancer_id = linode_nodebalancer.loadbalancer1.id
  config_id       = linode_nodebalancer_config.loadbalancer1_internal.id

  label   = format("internal-backend-%d", count.index + 1)
  address = format("%s:%d",
    element(linode_instance.workerpool1.*.private_ip_address, count.index),
    var.internal_backend_port,
  )
}
# ...

Debug Output

╷
│ Error: missing expected [
│ 
│   with linode_nodebalancer.loadbalancer1,
│   on loadbalancer1.tf line 1, in resource "linode_nodebalancer" "loadbalancer1":
│    1: resource "linode_nodebalancer" "loadbalancer1" { <- this curly brace is underlined
│ 
╵
2021-06-07T15:58:15.378+0530 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021-06-07T15:58:15.380+0530 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/linode/linode/1.18.0/darwin_amd64/terraform-provider-linode_v1.18.0 pid=89119
2021-06-07T15:58:15.380+0530 [DEBUG] provider: plugin exited

Expected Behavior

I did a terraform -chdir=./deploy/terraform apply with terraform-provider-linode_v1.13.4. No issue with nodebalancer. It should have stayed the same with terraform-provider-linode_v1.18.0.

Actual Behavior

Then I upgraded from terraform-provider-linode_v1.13.4 to terraform-provider-linode_v1.18.0.

Now, terraform -chdir=./deploy/terraform apply gives the reported error.

Gurpartap commented 3 years ago

Getting the error with plugin v1.14.3 too. Downgraded back to v1.13.4 and it reports no changes in the plan successfully.

LBGarber commented 3 years ago

Hello! Thanks for the report! 😃

It looks like this is result of these two breaking changes: transfer changed from TypeMap to TypeList node_status changed from TypeMap to TypeList

Currently the provider doesn't implement the StateUpgraders required to automate these tfstate upgrades, but this can be worked around manually removing or updating the transfer and node_status fields in your tfstate.

Gurpartap commented 3 years ago

Hello @LBGarber!

I have these in my tfstate. They appear to be in the expected structure as per the docs (linked). Should they be structured any differently?

linode_nodebalancer#transfer

"transfer": {
  "in": "5069.951974868774",
  "out": "4863.174536705017",
  "total": "9933.126511573792"
},

linode_nodebalancer_config#node_status

"node_status": {
  "down": "0",
  "up": "5"
},
Gurpartap commented 3 years ago

Full view of the two resources:

…

{
  "mode": "managed",
  "type": "linode_nodebalancer",
  "name": "loadbalancer1",
  "provider": "provider[\"registry.terraform.io/linode/linode\"]",
  "instances": [
    {
      "schema_version": 0,
      "attributes": {
        "client_conn_throttle": 0,
        "created": "2019-06-21T12:08:35Z",
        "hostname": "nb-1.2.3.4.dallas.nodebalancer.linode.com",
        "id": "1234",
        "ipv4": "1.2.3.4",
        "ipv6": "a:b:c::d:e",
        "label": "loadbalancer1",
        "region": "us-central",
        "tags": [],
        "transfer": {
          "in": "5069.951974868774",
          "out": "4863.174536705017",
          "total": "9933.126511573792"
        },
        "updated": "2019-06-22T14:03:38Z"
      },
      "sensitive_attributes": []
    }
  ]
},
{
  "mode": "managed",
  "type": "linode_nodebalancer_config",
  "name": "loadbalancer1_internal",
  "provider": "provider[\"registry.terraform.io/linode/linode\"]",
  "instances": [
    {
      "schema_version": 0,
      "attributes": {
        "algorithm": "roundrobin",
        "check": "http",
        "check_attempts": 2,
        "check_body": "",
        "check_interval": 10,
        "check_passive": true,
        "check_path": "/haproxy/monitor",
        "check_timeout": 3,
        "cipher_suite": "recommended",
        "id": "4321",
        "node_status": {
          "down": "0",
          "up": "5"
        },
        "nodebalancer_id": 1234,
        "port": 3000,
        "protocol": "http",
        "proxy_protocol": "none",
        "ssl_cert": null,
        "ssl_commonname": "",
        "ssl_fingerprint": "",
        "ssl_key": "",
        "stickiness": "none"
      },
      "sensitive_attributes": [],
      "dependencies": [
        "linode_nodebalancer.loadbalancer1"
      ]
    }
  ]
},

…

The current tfstate (v1.13.4) and the backup tfstate (before ever trying the upgraded plugins) are identical.

LBGarber commented 3 years ago

@Gurpartap Good catch on the docs, I'll make sure to get those updated!

For the newer versions of the provider:

"transfer": {
  "in": "5069.951974868774",
  "out": "4863.174536705017",
  "total": "9933.126511573792"
},

should become

"transfer": [
  {
    "in": 5069.951974868774,
    "out": 4863.174536705017,
    "total": 9933.126511573792
  }
],

and

"node_status": {
  "down": "0",
  "up": "5"
},

should become

"node_status": [
  {
    "down": 0,
    "up": 5
  }
],

Let me know if you run into any more issues! 😄