resource "google_compute_instance_template" "envoy_instance_template" {
disk {
source_image = "gce-uefi-images/cos-stable"
disk_size_gb = var.disk_size
disk_type = var.disk_type
boot = true
}
metadata = {
gce-container-declaration = yamlencode({
apiVersion = "v1",
kind = "Pod",
metadata = {
name = "envoy"
}
spec = {
containers = [{
name = "envoy",
image = "myimage",
imagePullPolicy = "Always",
ports = {
containerPort = "443",
hostPort = "443",
},
env = [
{
name = "ENVOY_CONFIG",
value = templatefile("${path.module}/envoy.tmpl",
{
routes = var.envoy_config.routes
clusters = var.envoy_config.clusters
}),
}
]
}]
}
})
google-logging-enabled = "TRUE"
enable-oslogin = "TRUE"
}
I simply want to start a docker container on top of gce-uefi-images/cos-stable
.
With the above code, the above gets started as expected.
However, the newline characters and indentation in ENVOY_CONFIG
is gone when the container starts.
The templatefile
function works correctly and produce a yaml
file which is expected.
However, inside the container ENVOY_CONFIG
loses all the indentation.
I tried using yamlencode
but it didn't work either.
What's the correct way to preserve the yaml file content (indentation and newline characters) in the environment variable ENVOY_CONFIG
?