How to convert yaml configmap file to terraform

3/28/2019

I am trying to integrate Kubewatch in a kubernetes cluster. The cluster was built using Terraform's kubernetes provider. How do I convert the data section of this configmap yaml file to terraform?

YAML
apiVersion: v1
kind: ConfigMap
metadata:
  name: kubewatch
data:
  .kubewatch.yaml: |
    namespace: "default"
    handler:
      slack:
        token: xoxb-OUR-BOT-TOKEN
        channel: kubernetes-events
    resource:
      deployment: true
      replicationcontroller: false
      replicaset: false
      daemonset: false
      services: true
      pod: true
      secret: true
      configmap: false
-- Oluwasegun Matthews
kubernetes
terraform

1 Answer

3/28/2019

While I haven't done very complex config maps, this should get you pretty close.

resource "kubernetes_config_map" "example" {
  metadata {
    name = "kubewatch"
  }

  data {
    namespace = "default"
    handler {
        slack {
            token   = "xoxb-OUR-BOT-TOKEN"
            channel = "kubernetes-events"
        }
    } 
    resource {
       deployment            = true
       replicationcontroller = false
       replicaset            = false
       daemonset             = false
       services              = true
       pod                   = true
       secret                = true
       configmap             = false
    }
    api_host = "myhost:443"
    db_host  = "dbhost:5432"
  }
}
-- Jamie
Source: StackOverflow