Skip to content

docker_config_json does not work with bootstrap_env vars #1727

@mustafa89

Description

@mustafa89

Description

Passing docker_config_json results in the EKS node not being able to join the cluster. Caused because printf strips the slashes \ in the encoded json.

locals {
docker_config_json = <<JSON
  {
    "bridge": "none",
    "log-driver": "json-file",
    "log-opts": {
      "max-size": "10m",
      "max-file": "10"
    },
    "live-restore": true,
    "max-concurrent-downloads": 10
  }
JSON
}

replace strips the empty spaces.

jsonencode(replace(local.docker_config_json, "/[[:space:]]/", ""))

outputs:

"{\"bridge\":\"none\",\"log-driver\":\"json-file\",\"log-opts\":{\"max-size\":\"10m\",\"max-file\":\"10\"},\"live-restore\":true,\"max-concurrent-downloads\":10}"

When the above is passed to the userdata script.
printf strips the escapes, and export strips the quotes "" resulting in a malformed json object and docker service failing to start.

I've tried all the bash alchemy I know, If there is a way to accomplosh this where i could populate the json object properly in the environment, it would be very nice.

Removing the printf and replacing it with a cat heredoc file insertion could fix this I believe keeping the escaping intact and the export would then inject a properly formated json object in the environment.

⚠️ Note

  • Behavior was tested on bash shell. (behaves differently on zsh)
  • Tried without jsonencode. tried adding quotes to the json object inside the local as well.
  • Not using a custom AMI

Versions

Terraform: 0.13.6
Provider(s): AWS: 3.63.0
Module: 17.23.0

Reproduction

Add the following to the node group definition as well as the local defined in the description

 bootstrap_env = {
           DOCKER_CONFIG_JSON = jsonencode(replace(local.docker_config_json, "/[[:space:]]/", ""))
  }

EKS node won't be able to join the cluster. SSH in to the node and look insde /etc/docker/daemon.json we can see the malformed json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions