Skip to content

variable create --key flag cannot handle values containing ${} (Cobra StringToStringVar limitation) #201

@Raymondhou0917

Description

@Raymondhou0917

Bug Description

When using variable create --key to set environment variables containing Zeabur variable references like ${POSTGRESQL.POSTGRES_CONNECTION_STRING}, the value gets truncated or emptied.

Steps to Reproduce

npx zeabur@latest variable create \
  --id <service-id> \
  --key 'DATABASE_URL=${POSTGRESQL.POSTGRES_CONNECTION_STRING}' \
  -i=false --json

Expected: DATABASE_URL set to ${POSTGRESQL.POSTGRES_CONNECTION_STRING}
Actual: DATABASE_URL set to empty string ""

Even with single quotes, the value is lost. The same issue affects variable update.

Root Cause

The --key flag uses Cobra's StringToStringVarP which parses KEY=VALUE pairs using an internal CSV parser. This parser cannot handle values containing ${}, commas, or other special characters.

Source: /internal/cmd/variable/create/create.go

cmd.Flags().StringToStringVarP(&opts.keys, "key", "k", nil, "Key value pair of the variable")

Suggested Fix

Switch from StringToStringVarP to StringArrayVarP, then manually split each entry on the first = only (similar to how Helm handles --set flags). This preserves arbitrary characters in values.

// Before
cmd.Flags().StringToStringVarP(&opts.keys, "key", "k", nil, "...")

// After
var rawKeys []string
cmd.Flags().StringArrayVarP(&rawKeys, "key", "k", nil, "...")
// Then in Run: split each on first "=" 
for _, kv := range rawKeys {
    parts := strings.SplitN(kv, "=", 2)
    key, value := parts[0], parts[1]
}

Alternatively, support --env-file for loading variables from a file.

Workaround

Use GraphQL API updateEnvironmentVariable(serviceID, environmentID, data: Map!) mutation directly, passing the value via JSON (no shell escaping issues).

Environment

  • CLI version: 0.14.0
  • OS: macOS (Apple Silicon)
  • Shell: zsh

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