Skip to content

Conversation

@matifali
Copy link
Member

Problem

The Zed module's settings parsing was broken. The previous implementation used quote escaping:

SETTINGS_JSON='${replace(var.settings, "\"", "\\\"")}'

This produced invalid JSON like {\"theme\":\"dark\"} which jq could not parse because the backslash-escaped quotes are not valid JSON syntax.

Solution

Changed to use base64 encoding internally:

locals {
  settings_b64 = var.settings != "" ? base64encode(var.settings) : ""
}

# In the script:
SETTINGS_B64='${local.settings_b64}'
SETTINGS_JSON="$(echo -n "${SETTINGS_B64}" | base64 -d)"

User interface remains the same - users still provide plain JSON via jsonencode() or heredoc:

module "zed" {
  source   = "..."
  agent_id = coder_agent.main.id
  settings = jsonencode({
    theme    = "dark"
    fontSize = 14
  })
}

Testing

Added comprehensive tests:

Terraform tests (5):

  • URL generation (default, folder, agent_name)
  • Settings base64 encoding verification
  • Empty settings edge case

Container e2e tests (3):

  • Creates settings file with correct JSON (including special chars: quotes, backslashes, URLs)
  • Merges with existing settings via jq
  • Exits early with empty settings

Also fixed existing tests to use override_data for proper workspace mocking.

The previous implementation used quote escaping which produced invalid JSON:
  SETTINGS_JSON='{"theme":"dark"}'

This broke jq parsing because the escaped quotes are not valid JSON.

Changed to use base64 encoding internally:
  settings_b64 = base64encode(var.settings)
  SETTINGS_JSON="$(echo -n "${SETTINGS_B64}" | base64 -d)"

User interface remains the same - pass JSON via jsonencode() or heredoc.

Also added end-to-end container tests and fixed existing tests to use
override_data for workspace mocking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant