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

Better logging of state parsing errors #13

Open
silvpol opened this issue Oct 27, 2020 · 0 comments
Open

Better logging of state parsing errors #13

silvpol opened this issue Oct 27, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@silvpol
Copy link

silvpol commented Oct 27, 2020

I have come across an issue when cluster was upgraded from 1.15 to 1.16 and the config stopped working. I have updated the TF files to match the new format but plan keeps failing with a rather unhelpful message:

Error: missing expected [

Enabling Terraform TRACE logging didn't yield any clues and the only way I could spot the issue was to create another environment and compare state files.

I don't think there is a solution to migrate spec format here but a more detailed message with parsing error and some context would have allowed to pinpoint issue much quicker.

I'm using:

Terraform version: 0.12.20
terraform-provider-k8s_v0.1.4
Kubernetes 1.15 / 1.16

Resource in 1.15:

resource "k8s_cloud_google_com_v1beta1_backend_config" "www" {

  metadata {
    name      = "www"
    namespace = var.namespace
  }

  spec = jsonencode({
    timeoutSec = 600
  spec {
    timeout_sec = 600

    connectionDraining = {
      drainingTimeoutSec = 121
    connection_draining {
      draining_timeout_sec = 121
    }

    cdn = {
    cdn {
      enabled = true

      cachePolicy = {
        includeHost        = true
        includeProtocol    = true
        includeQueryString = true
      cache_policy {
        include_host         = true
        include_protocol     = true
        include_query_string = true
      }
    }
  })
  }
}

Same resource in 1.16:

resource "k8s_cloud_google_com_v1beta1_backend_config" "www" {

  metadata {
    name      = "www"
    namespace = var.namespace
  }

  spec {
    timeout_sec = 600

    connection_draining {
      draining_timeout_sec = 121
    }

    cdn {
      enabled = true

      cache_policy {
        include_host         = true
        include_protocol     = true
        include_query_string = true
      }
    }
  }
}

State fragment in 1.15:

    {
      "mode": "managed",
      "type": "k8s_cloud_google_com_v1beta1_backend_config",
      "name": "www",
      "provider": "provider.k8s",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "test.backend_config.www",
            "metadata": [
              {
                "annotations": {},
                "creation_timestamp": "2020-03-31T08:32:16Z",
                "deletion_grace_period_seconds": 0,
                "deletion_timestamp": "",
                "labels": {},
                "name": "www",
                "namespace": "test",
                "resource_version": "8569",
                "self_link": "/apis/cloud.google.com/v1beta1/namespaces/test/backendconfigs/www",
                "uid": "39592fd1-83b7-48ac-af98-9497c4a5c9dc"
              }
            ],
            "spec": "{\"cdn\":{\"cachePolicy\":{\"includeHost\":true,\"includeProtocol\":true,\"includeQueryString\":true},\"enabled\":true},\"connectionDraining\":{\"drainingTimeoutSec\":121},\"timeoutSec\":600}"
          },
          "private": "bnVsbA=="
        }
      ]
    },

State fragment in 1.16:

    {
      "mode": "managed",
      "type": "k8s_cloud_google_com_v1beta1_backend_config",
      "name": "www",
      "provider": "provider.k8s",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "kube.backend_config.www",
            "metadata": [
              {
                "annotations": {},
                "creation_timestamp": "2020-10-26T20:05:01Z",
                "deletion_grace_period_seconds": 0,
                "deletion_timestamp": "",
                "labels": {},
                "name": "www",
                "namespace": "kube",
                "resource_version": "100795599",
                "self_link": "/apis/cloud.google.com/v1beta1/namespaces/kube/backendconfigs/www",
                "uid": "87c19eed-6aae-4cb9-a86a-1dae1b319bb4"
              }
            ],
            "spec": [
              {
                "cdn": [
                  {
                    "cache_policy": [
                      {
                        "include_host": "true",
                        "include_protocol": "true",
                        "include_query_string": "true",
                        "query_string_blacklist": [],
                        "query_string_whitelist": []
                      }
                    ],
                    "enabled": "true"
                  }
                ],
                "connection_draining": [
                  {
                    "draining_timeout_sec": 121
                  }
                ],
                "custom_request_headers": [],
                "health_check": [],
                "iap": [],
                "logging": [],
                "security_policy": [],
                "session_affinity": [],
                "timeout_sec": 600
              }
            ]
          },
          "private": "bnVsbA=="
        }
      ]
    },
@mingfang mingfang added the enhancement New feature or request label Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants