variable "external_dns_k8s_namespace" {
  type = string
}

variable "external_dns_k8s_service_account" {
  type = string
}

variable "external_dns_gcp_service_account_email" {
  type = string
}

data "google_client_config" "default" {}

provider "kubernetes" {
  host  = "https://${google_container_cluster.cluster.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint}"
  token = data.google_client_config.default.access_token

  ignore_annotations = [
    "^autopilot\\.gke\\.io\\/.*",
    "^cloud\\.google\\.com\\/.*"
  ]
}

module "workload" {
  count                                  = var.cluster_exists ? 1 : 0
  source                                 = "../k8s_workload"
  project                                = var.project
  region                                 = var.region
  cluster                                = google_container_cluster.cluster
  node_pool                              = google_container_node_pool.node_pool
  external_dns_k8s_namespace             = var.external_dns_k8s_namespace
  external_dns_k8s_service_account       = var.external_dns_k8s_service_account
  external_dns_gcp_service_account_email = var.external_dns_gcp_service_account_email
  dns_managed_zone                       = var.dns_managed_zone
  public_ingress                         = var.public_ingress
  ingress_type                           = var.ingress_type
  enable_snat                            = var.enable_snat
  main_k8s_namespace                     = var.main_k8s_namespace
}