hashicorp / terraform-provider-kubernetes-alpha

A Terraform provider for Kubernetes that uses dynamic resource types and server-side apply. Supports all Kubernetes resources.
https://registry.terraform.io/providers/hashicorp/kubernetes-alpha/latest
Mozilla Public License 2.0
490 stars 63 forks source link

panic: interface conversion: tftypes.Type is tftypes.primitive, not tftypes.Object #175

Open lawliet89 opened 3 years ago

lawliet89 commented 3 years ago

Terraform, Provider, Kubernetes versions

Terraform version: 0.14.8
Provider version: 0.3.1
Kubernetes version: v1.18.12-gke.1210

Affected Resource(s)

Terraform Configuration Files

provider "google" {
  region  = var.region
  project = var.project_id
}

provider "kubernetes-alpha" {
  host                   = "https://${coalesce(var.kubernetes_host, data.terraform_remote_state.gke.outputs.endpoint)}"
  token                  = data.google_client_config.default.access_token
  cluster_ca_certificate = coalesce(var.kubernetes_ca_certificate, base64decode(data.terraform_remote_state.gke.outputs.ca_certificate))
}

data "google_client_config" "default" {
}

data "terraform_remote_state" "gke" {
  backend = "gcs"

  config = {
    bucket = var.remote_state_bucket
    prefix = "gke"
  }
}

locals {
  internal_name = join("-", ["ambassador", "internal"])
  external_name = join("-", ["ambassador", "external"])
}

# Cannot specify separate configuration per Ambassador
# See https://github.com/datawire/ambassador/issues/2283
resource "kubernetes_manifest" "configuration" {
  provider = kubernetes-alpha

  manifest = {
    apiVersion = "getambassador.io/v2"
    kind       = "Module"

    metadata = {
      name      = "ambassador"
      namespace = "core"
      labels = {
        "app.kubernetes.io/instance"   = local.internal_name
        "app.kubernetes.io/managed-by" = "Terraform"
        "app.kubernetes.io/name"       = "ambassador"
        "app.kubernetes.io/part-of"    = local.internal_name
      }
    }

    spec = {
      ambassador_id = ["internal", "external"]
      config = {
        # Rate limit labels: see https://www.getambassador.io/docs/latest/topics/using/rate-limits/rate-limits/
        default_label_domain = "ambassador"
        default_labels = {
          ambassador = {
            defaults = [
              "remote_address",
            ]
          }
        }

        envoy_log_type = "json"
        envoy_log_format = {
          authority                         = "%REQ(:AUTHORITY)%",
          bytes_received                    = "%BYTES_RECEIVED%",
          bytes_sent                        = "%BYTES_SENT%",
          downstream_local_address          = "%DOWNSTREAM_LOCAL_ADDRESS%",
          downstream_remote_address         = "%DOWNSTREAM_REMOTE_ADDRESS%",
          duration                          = "%DURATION%",
          method                            = "%REQ(:METHOD)%",
          path                              = "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%",
          protocol                          = "%PROTOCOL%",
          request_id                        = "%REQ(X-REQUEST-ID)%",
          requested_server_name             = "%REQUESTED_SERVER_NAME%",
          response_code                     = "%RESPONSE_CODE%",
          response_code_details             = "%RESPONSE_CODE_DETAILS%"
          response_flags                    = "%RESPONSE_FLAGS%",
          start_time                        = "%START_TIME%",
          upstream_cluster                  = "%UPSTREAM_CLUSTER%",
          upstream_host                     = "%UPSTREAM_HOST%",
          upstream_local_address            = "%UPSTREAM_LOCAL_ADDRESS%",
          upstream_service_time             = "%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%",
          upstream_transport_failure_reason = "%UPSTREAM_TRANSPORT_FAILURE_REASON%",
          user_agent                        = "%REQ(USER-AGENT)%",
          x_forwarded_for                   = "%REQ(X-FORWARDED-FOR)%"
        }
      }
    }
  }
}
resource "kubernetes_manifest" "internal_consul_resolver" {
  provider = kubernetes-alpha

  manifest = {
    apiVersion = "getambassador.io/v2"
    kind       = "ConsulResolver"

    metadata = {
      name      = join("-", [local.internal_name, "consul"])
      namespace = "core"
      labels = {
        "app.kubernetes.io/instance"   = local.internal_name
        "app.kubernetes.io/managed-by" = "Terraform"
        "app.kubernetes.io/name"       = "ambassador"
        "app.kubernetes.io/part-of"    = local.internal_name
      }
    }

    spec = {
      ambassador_id = "internal"
      address       = "$${HOST_IP}:8501"
      datacenter    = "asia-southeast1"
    }
  }
}

resource "kubernetes_manifest" "external_consul_resolver" {
  provider = kubernetes-alpha

  manifest = {
    apiVersion = "getambassador.io/v2"
    kind       = "ConsulResolver"

    metadata = {
      name      = join("-", [local.external_name, "consul"])
      namespace = "core"
      labels = {
        "app.kubernetes.io/instance"   = local.external_name
        "app.kubernetes.io/managed-by" = "Terraform"
        "app.kubernetes.io/name"       = "ambassador"
        "app.kubernetes.io/part-of"    = local.external_name
      }
    }

    spec = {
      ambassador_id = "external"
      address       = "$${HOST_IP}:8501"
      datacenter    = "asia-southeast1"
    }
  }
}
variable "region" {
  description = "Default region for GCP"
  default     = "asia-southeast1"
}

variable "project_id" {
  description = "Project ID to deploy resources in"
}

variable "remote_state_bucket" {
  description = "GCS bucket where the remote state is stored"
}

variable "kubernetes_host" {
  description = "Kubernetes Host"
  default     = ""
}

variable "kubernetes_ca_certificate" {
  description = "Kubernetes CA Certificate"
  default     = ""
}
terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 3.0"
    }
    kubernetes-alpha = {
      source  = "hashicorp/kubernetes-alpha"
      version = "~> 0.3.0, >= 0.3.1"
    }
  }
  required_version = ">= 0.13"
}

Debug Output

https://gist.github.com/lawliet89/b737075f8e471227cf3e0d3f655fa082#file-gistfile1-txt

Panic Output

https://gist.github.com/lawliet89/b737075f8e471227cf3e0d3f655fa082#file-crash-log

Steps to Reproduce

  1. terraform plan

Expected Behavior

What should have happened?

  1. A plan to be output.

Actual Behavior

What actually happened?

  1. Crash

Important Factoids

References

Community Note

ggolub commented 3 years ago

Got the same error. Source code and crash report in this gist: https://gist.github.com/ggolub/cbfef54efee7ad33beacd68daaf89751

Used minikube for this test which I first hit in AKS.