Skip to content

Commit 6eece81

Browse files
authored
Merge pull request #99 from DefangLabs/eric-update-for-interpolation
add interpolation to docs
2 parents 515e946 + 0025b38 commit 6eece81

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

docs/concepts/configuration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ services:
4444
4545
Use the `defang config` command of the Defang CLI to manage the values.
4646

47+
## Interpolation
48+
49+
Environment variables are set within the *environment* section of a service in a `compose.yaml` file. Any variables declared here will become available within the service container.
50+
51+
Variables can be set by assigning a literal value, a reference to a configuration value, or a mix of literal and variable references. Variable references are declared using either **\$\{variable_name\}** or **$variable_name** forms. It is recommended to use the bracketed form. By interpolating over variable references within a string we can construct complex strings. Interpolation may be particularly useful when constructing connection strings to other services.
52+
53+
```
54+
service:
55+
environment:
56+
- USER_PASSWORD // configuration variable
57+
- USER_NAME // configuration variable
58+
- CONNECT=dbservice:${USER_NAME}:${USER_PASSWORD}@example.com:9876
59+
```
60+
In the example above, if we assume the value of the configuration variable ***USER_PASSWORD*** is *password* then the value assigned to ***CONNECT*** will resolve to *dbservice:alice:[email protected]:9876*
61+
62+
63+
During `defang compose up` all variable references will be replaced with the actual value and made available in the container. If any referenced variable is not found the `defang compose up` command will be canceled.
64+
4765
## Connecting Services
4866
4967
If you have created a service before a secret you can connect it by running the `defang compose start` command if using the [`defang compose` workflow](./compose.md). If you are using the [Pulumi-based workflow](./pulumi.md) you will need to redeploy using Pulumi.
@@ -57,3 +75,5 @@ You can find a sample of how to set sensitive config values [here](https://githu
5775
Here are the different ways sensitive config values are stored depending on the provider you are using:
5876
5977
* [AWS](../providers/aws/aws.md#secrets)
78+
79+

docs/concepts/managed-storage/managed-postgres.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ You can connect to the managed Postgres instance using the name of your service
4949
# value set using `defang config set POSTGRES_PASSWORD`
5050
POSTGRES_PASSWORD:
5151
// highlight-end
52+
# Note: you can create a connection string by using interpolation,
53+
# reference config variables by using ${<config name>}
54+
CONNECTURL: postgresql://${POSTGRES_PASSWORD}@database:5432/postgres
5255
database:
5356
image: postgres:15
5457
x-defang-postgres: true

0 commit comments

Comments
 (0)