env-file
A reference page for the env-file resource
The env-file resource manages a single .env file at a specified directory. It supports writing key-value pairs directly or syncing the file from Codify cloud. The resource is marked sensitive and will not be automatically imported.
Parameters
- dir (string, required): The directory where the env file is located.
- name (string, optional): The filename. Defaults to
.env. Use this to manage files like.env.local,.dev.vars, or.env.production. - contents (array[object], optional): Key-value pairs to write into the file. Each entry has
key(string) andvalue(string). Mutually exclusive withremoteFile. - remoteFile (string, optional): A Codify cloud file reference (
codify://<documentId>:<fileName>). The file is downloaded and written on each apply. Mutually exclusive withcontents.
Example usage
Declare env file contents
[
{
"type": "env-file",
"dir": "~/projects/my-app",
"contents": [
{ "key": "DATABASE_URL", "value": "postgres://localhost:5432/mydb" },
{ "key": "API_KEY", "value": "<Replace me here!>" },
{ "key": "DEBUG", "value": "false" }
]
}
]Use a named env file
[
{
"type": "env-file",
"dir": "~/projects/my-worker",
"name": ".dev.vars",
"contents": [
{ "key": "API_TOKEN", "value": "<Replace me here!>" }
]
}
]Sync from Codify cloud
[
{
"type": "env-file",
"dir": "~/projects/my-app",
"name": ".env.local",
"remoteFile": "codify://<documentId>:<fileName>"
}
]Notes
- The resource is marked as sensitive: values in
contentsare not shown in plan output. - Import is disabled (
preventImport: true) — existing.envfiles on the system are never automatically imported. - Both
contentsandremoteFilecannot be specified at the same time. - Multiple
env-fileresources can coexist in the same directory as long as they use differentnamevalues.