Skip to content

Commit 7081cb5

Browse files
committed
Added docs for spin up --variable
Signed-off-by: itowlson <[email protected]>
1 parent c766223 commit 7081cb5

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

content/v3/variables.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ url = "https://github.com/spinframework/spin-docs/blob/main/content/v3/variables
88
---
99
- [Adding Variables to Your Applications](#adding-variables-to-your-applications)
1010
- [Using Variables From Applications](#using-variables-from-applications)
11+
- [Providing Variable Values](#providing-variable-values)
12+
- [Providing Variable Values from a Secrets Store](#providing-variable-values-from-a-secrets-store)
13+
- [Providing Variable Values from the Environment](#providing-variable-values-from-the-environment)
14+
- [Providing Variable Values on the Command Line](#providing-variable-values-on-the-command-line)
1115
- [Troubleshooting](#troubleshooting)
1216

1317
Spin supports dynamic application variables. Instead of being static, their values can be updated without modifying the application, creating a simpler experience for rotating secrets, updating API endpoints, and more.
1418

15-
These variables are defined in a Spin application manifest (in the `[variables]` section), and their values can be set or overridden at runtime by an [application variables provider](./dynamic-configuration.md#application-variables-runtime-configuration). When running Spin locally, the variables provider can be [Hashicorp Vault](./dynamic-configuration.md#vault-application-variable-provider) for secrets, [Azure Key Vault](https://azure.microsoft.com/en-us/products/key-vault), or host environment variables.
16-
17-
For information about configuring application variables providers, refer to the [runtime configuration documentation](./dynamic-configuration.md#application-variables-runtime-configuration).
19+
These variables are defined in a Spin application manifest (in the `[variables]` section), and their values can be set or overridden at runtime by an [application variables provider](./dynamic-configuration.md#application-variables-runtime-configuration), or the `--variable` flag to `spin up`. When running Spin locally, the variables provider can be [Hashicorp Vault](./dynamic-configuration.md#vault-application-variable-provider) for secrets, [Azure Key Vault](https://azure.microsoft.com/en-us/products/key-vault), or host environment variables. [See below](#setting-variable-values) for more information.
1820

1921
## Adding Variables to Your Applications
2022

@@ -275,6 +277,47 @@ date: Wed, 31 Jul 2024 22:03:35 GMT
275277
Used an API
276278
```
277279

280+
## Providing Variable Values
281+
282+
When you run an application, you must provide values for all required variables, and you may provide values for non-required variables (where you want to override the default). You can do this using a provider such as a secrets store, or you can set variables directly on the `spin up` command line.
283+
284+
### Providing Variable Values from a Secrets Store
285+
286+
You can provide variable values from a secrets store. The Spin CLI supports [Hashicorp Vault](./dynamic-configuration.md#vault-application-variable-provider) and [Azure Key Vault](https://azure.microsoft.com/en-us/products/key-vault). If you want to do this, you must set up the store in the runtime configuration file, and reference that file using `--runtime-config-file` on the command line.
287+
288+
For information about configuring application variables providers, refer to the [runtime configuration documentation](./dynamic-configuration.md#application-variables-runtime-configuration).
289+
290+
### Providing Variable Values from the Environment
291+
292+
You can provide variable values using the operating system environment. For each variable you want to set, you must specify an environment variable named `SPIN_VARIABLE_` folloed by a "shouty capitalised" form of the variable name - that is, all uppercase, with underscores for separators. For example, to set the `database_username` variable:
293+
294+
```console
295+
$ export SPIN_VARIABLE_DATABASE_USERNAME=bob_the_admin
296+
$ spin up
297+
```
298+
299+
### Providing Variable Values on the Command Line
300+
301+
You can provide variable values via the `spin up --variable` command line flag. This flag can be repeated, and supports several variants:
302+
303+
* `<key>=<value>`: sets the `<key>` variable to the given value
304+
* `<key>=@<file>`: sets the `<key>` variable to the contents of the given text file
305+
* `@<file>.json`: sets multiple variables - each `"<key>": "<value>"` pair in the given JSON file sets the `<key>` variable to the corresponding value
306+
* `@<file>.toml`: sets multiple variables - each `<key> = "<value>"` pair in the given TOML file sets the `<key>` variable to the corresponding value
307+
308+
For example, suppose `secrets.json` is as follows:
309+
310+
```json
311+
{
312+
"sierra_madre": "no spoilers",
313+
"eleven_herbs_and_spices": "you will never learn them from us"
314+
}
315+
```
316+
317+
Then `spin up --variable @secrets.json` will set the `sierra_madre` and `eleven_herbs_and_spices` variables. (Similarly with TOML files.)
318+
319+
For the `@<file>.json` and `@<file>.toml` variants, the file content must be string keys to string values. Numeric or object/table values are not allowed.
320+
278321
## Troubleshooting
279322

280323
**"No provider resolved" error**

0 commit comments

Comments
 (0)