> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/cli/guides/secrets/fill-a-template.md).

# Fill a configuration file from a template

Generate a configuration file from a template with devo:// references, with devo secret inject, for tools that can't read secrets from the environment.

Some tools only read their settings from a file, like `appsettings.json`, a YAML configuration, or a `.npmrc`. With `devo secret inject`, you keep a template with `devo://` references in your repository, and generate the real file when you need it.

{% hint style="warning" %}
The file that `devo secret inject` produces contains your secrets in plain text. Use it only when the tool can't take its secrets from the environment, delete it when you're done, and never commit it. If the tool can read environment variables, use [devo secret run](/cli/guides/secrets/run-with-secrets.md) instead: the values then never touch the disk.
{% endhint %}

## Write the template

Put a reference wherever a secret goes. Wrap it in `{{ }}` so Devolutions CLI knows exactly where it starts and ends:

```json
{
  "Database": {
    "User": "{{ devo://ws/<workspace-id>/vault/<vault-id>/entry/<entry-id>/field/username }}",
    "Password": "{{ devo://ws/<workspace-id>/vault/<vault-id>/entry/<entry-id>/field/password }}"
  }
}
```

A reference without `{{ }}` also works. It ends at the first space, quote, `<`, `>`, `)`, `]`, or `}`.

Inside a reference, `$NAME`, `${NAME}`, and `${NAME:-default}` are replaced by the value of an environment variable before the reference is resolved. Use this to share one template between environments, for example `devo://ws/${WORKSPACE_ID}/vault/…`.

## Generate the file

```bash
devo secret inject --in-file appsettings.template.json --out-file appsettings.json
```

<table><thead><tr><th width="200">OPTION</th><th>WHAT IT DOES</th></tr></thead><tbody><tr><td><code>--in-file</code>, <code>-i</code></td><td>The template to read. Without it, Devolutions CLI reads the template from standard input.</td></tr><tr><td><code>--out-file</code>, <code>-f</code></td><td>The file to write. Without it, the result goes to standard output.</td></tr><tr><td><code>--force</code></td><td>Replaces the output file if it already exists. Without it, the command stops before reading any secret.</td></tr></tbody></table>

You can also work with pipes, for example to pass the result straight to another program:

```bash
cat config.template.yaml | devo secret inject | <your-tool> --config -
```

{% hint style="warning" %}
If a reference can't be resolved, the next program in the pipe receives the summary line `References: <resolved>/<total> resolved` instead of your configuration. In a script, check the exit code of `devo secret inject`, or write to a file with `--out-file`.
{% endhint %}

## What you can rely on

* **All or nothing.** If one reference can't be resolved, Devolutions CLI writes no file and none of the template. It lists the errors on standard error, prints a summary line such as `References: 1/2 resolved` on standard output, and exits with code `1`.
* **Private file.** The output file is created with private permissions: on macOS and Linux, only your user account can read it; on Windows, your account, the system account, and administrators.
* **No half-written file.** Devolutions CLI writes to a temporary file in the same folder, then moves it into place.
* **Each reference is read once.** A reference used several times in the template is resolved once.

With `--output json`, the command returns a summary instead of the content: how many references it found and resolved. The values aren't in it.

## Good to know

* With standard output, the values appear in your terminal or in whatever reads the pipe. Prefer `--out-file` when you don't need a pipe.
* References resolve through the current context. Add `--context <context-name>` to use another workspace. Canonical references always resolve against the workspace that owns them.
* A reference doesn't resolve: see [A secret reference doesn't resolve](/cli/help/troubleshooting/reference-does-not-resolve.md).

## Next

* [Take the passwords out of a .env file](/cli/guides/secrets/replace-env-files.md)
* [What stays hidden, and what doesn't](/cli/guides/understand/security-model.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/cli/guides/secrets/fill-a-template.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
