Kubernetes ConfigMap YAML into Terraform Kubernetes

7/17/2019

I am trying to convert the following ConfigMap yaml file (link here) into a kubernetes_config_map but am running into syntax errors when trying to define it.

In particular, I can't get around the dot notation inside the opentsdb.conf file

apiVersion: v1
kind: ConfigMap
metadata:
  name: opentsdb-config
data:
  opentsdb.conf: |
    google.bigtable.project.id = REPLACE_WITH_PROJECT
    google.bigtable.instance.id = REPLACE_WITH_INSTANCE
    google.bigtable.zone.id = REPLACE_WITH_ZONE
    hbase.client.connection.impl = com.google.cloud.bigtable.hbase1_2.BigtableConnection
    google.bigtable.auth.service.account.enable = true

    tsd.network.port = 4242
    tsd.core.auto_create_metrics = true
    tsd.core.meta.enable_realtime_ts = true
    tsd.core.meta.enable_realtime_uid = true
    tsd.core.meta.enable_tsuid_tracking = true
    tsd.http.request.enable_chunked = true
    tsd.http.request.max_chunk = 131072
    tsd.storage.fix_duplicates = true
    tsd.storage.enable_compaction = false
    tsd.storage.max_tags = 12
    tsd.http.staticroot = /opentsdb/build/staticroot
    tsd.http.cachedir = /tmp/opentsdb

This is my current attempt that is erroring out on the "opentsdb.conf"

resource "kubernetes_config_map" "opentsdb" {
  metadata {
    name = "opentsdb-config",
    namespace = "dev"
  }

  data {
    "opentsdb.conf" = {
      google.bigtable.project.id = var.project_id,
      google.bigtable.instance.id = google_bigtable_instance.development-instance.name,
      google.bigtable.zone.id = var.zone,
      hbase.client.connection.impl = "com.google.cloud.bigtable.hbase1_2.BigtableConnection",
      google.bigtable.auth.service.account.enable = true

      tsd.network.port = 4242
      tsd.core.auto_create_metrics = true
      tsd.core.meta.enable_realtime_ts = true
      tsd.core.meta.enable_realtime_uid = true
      tsd.core.meta.enable_tsuid_tracking = true
      tsd.http.request.enable_chunked = true
      tsd.http.request.max_chunk = 131072
      tsd.storage.fix_duplicates = true
      tsd.storage.enable_compaction = false
      tsd.storage.max_tags = 12
      tsd.http.staticroot = "/opentsdb/build/staticroot"
      tsd.http.cachedir = "/tmp/opentsdb"
    }
  }
}
-- ScottMcC
kubernetes
terraform
terraform-provider-gcp

2 Answers

7/22/2019

Welcome file Welcome file As was already mentioned by ydaetskcoR, you should fix your Terraform syntax and add quotations.

Here is a link to Configuration Syntax in Terraform.

A block is a container for other content:

resource "aws_instance" "example" {
  ami = "abc123"

  network_interface {
    # ...
  }
}

A block has a type (resource in this example). Each block type defines how many labels must follow the type keyword. The resource block type expects two labels, which are aws_instance and example in the example above. A particular block type may have any number of required labels, or it may require none as with the nested network_interface block type.

-- Crou
Source: StackOverflow

7/23/2019

The issue that I had is that I was trying to assign an object to a string literal.

I needed to use the EOF syntax as follows:

resource "kubernetes_config_map" "opentsdb" {
  metadata {
    name = "opentsdb-config"
    namespace = "dev"
  }

  data = {
    "opentsdb.conf" = <<EOF
google.bigtable.project.id = ${var.project_id}
google.bigtable.instance.id = ${var.bigtable_instance_id}
google.bigtable.zone.id = ${var.zone}
hbase.client.connection.impl = com.google.cloud.bigtable.hbase1_2.BigtableConnection
google.bigtable.auth.service.account.enable = true

tsd.network.port = 4242
tsd.core.auto_create_metrics = true
tsd.core.meta.enable_realtime_ts = true
tsd.core.meta.enable_realtime_uid = true
tsd.core.meta.enable_tsuid_tracking = true
tsd.http.request.enable_chunked = true
tsd.http.request.max_chunk = 131072
tsd.storage.fix_duplicates = true
tsd.storage.enable_compaction = false
tsd.storage.max_tags = 12
tsd.http.staticroot = /opentsdb/build/staticroot
tsd.http.cachedir = /tmp/opentsdb
    EOF
  }
}
-- ScottMcC
Source: StackOverflow