Why .env to YAML needs careful quoting
A .env value is always a string. YAML guesses types from unquoted text, and the guesses differ between YAML 1.1 (PyYAML, Ansible, older Kubernetes tooling) and YAML 1.2:
| .env value | Unquoted YAML 1.1 reads | Unquoted YAML 1.2 reads | Converter writes |
|---|---|---|---|
yes / no / on / off | boolean | string | "yes" (quoted) |
3.10 | number 3.1 | number 3.1 | "3.10" |
0123 | octal 83 | number 123 | "0123" |
a: b | a nested map | a nested map | "a: b" |
*star | an alias (error) | an alias (error) | "*star" |
3000 (coerce on) | number | number | 3000 |
The famous case is the "Norway problem": a list of country codes where NO silently became false. Quoting anything ambiguous avoids that class of bug entirely.
Using the output
Kubernetes ConfigMap
apiVersion: v1 kind: ConfigMap metadata: name: app-config data: # ConfigMap data values must be strings: turn coerce OFF NODE_ENV: production PORT: "3000"
GitHub Actions with secrets
env:
NODE_ENV: test # plain values from the converter
DATABASE_URL: ${{ secrets.DATABASE_URL }} # secrets stay in GitHubThe guide GitHub Actions secrets covers repository vs environment secrets and how to write a .env file inside a job. For Compose, the ENV to Docker converter also produces Dockerfile ENV lines and Kubernetes Secrets.
Converting back: YAML to .env
# flat YAML map -> .env (mikefarah/yq v4) yq -o=props '.' config.yaml | sed 's/ = /=/' > .env # or via JSON yq -o=json '.' config.yaml > config.json # then use the JSON to ENV converter
Nested YAML has to be flattened first; the JSON to ENV converter does that automatically with _ separators.