Terraform GCE and kubernetes

10/16/2017

I provision the Google container engine with terraform and I also use terraform Kubernetes provider. I have some docker images on private repo that I like to use kubernetes provider to pull but I have some difficulty to use image_pull_secrets.

resource "kubernetes_service_account" "example" {
  metadata {
    name = "terraform-example"
  }
  secret {
    name = "${kubernetes_secret.example.metadata.0.name}"
  }
}

resource "kubernetes_secret" "example" {
  metadata {
    name = "terraform-example"
  }
}

I am wondering what should I use for image_pull_secrets.

  resource "kubernetes_replication_controller" "xxx-rest-client" {
    metadata {
      name = "xxx-rest-client"
      labels {
        app = "xxx-rest-client"
      }
    }
    spec {
      replicas = 2
      selector {
        name = "xxx-rest-client"
      }
      template {
        image_pull_secrets   = ["${kubernetes_service_account.example.UNKNOWN}"]
        container {
          image               = "test/xxx-rest-client"
          name                = "xxx-rest-client"
          //port  = ["3128"]

          resources{
            limits{
              cpu    = "1.0"
              memory = "512Mi"
            }
            requests{
              cpu    = "250m"
              memory = "50Mi"
            }
          }
        }
      }
    }
     depends_on = ["google_container_cluster.xxx"]
  }
-- benjaminbutton
google-compute-engine
kubernetes
terraform

1 Answer

11/28/2017

Each element of the pull secrets list needs to be a map.

image_pull_secrets = [
  {
    name = "${kubernetes_service_account.example.default_secret_name}"
  }
]

Give that a try and it should work for you.

-- tazer84
Source: StackOverflow