faint-minister-59136
04/09/2025, 10:32 AMmicroscopic-river-74022
04/09/2025, 10:32 AMmicroscopic-river-74022
04/09/2025, 10:32 AMyaml
kind: Project
variables:
log-level: info
environments:
- name: local
variables:
log-level: debug
- name: remote
---
kind: Deploy
spec:
env:
LOG_LEVEL: ${var.log-level} # Resolves to "debug" for local environment
This approach allows you to define environment-specific values that can be referenced throughout your configuration [Project variables]().
## Environment Name Reference
You can reference the current environment name using the ${environment.name}
template string:
yaml
my-variable: ${environment.name}
This will resolve to the name of the environment Garden is running against [Environment name reference]().
## Setting Environment Variables for Services and Tasks
For container modules, you can set environment variables directly in the env
field:
yaml
services:
- name: my-service
env:
MY_VAR: some-value
MY_SECRET_VAR:
secretRef:
name: my-secret
key: some-key
This works for both services and tasks [Container services env]().
## Using Module Variables
You can also define variables at the module level and reference them within the module:microscopic-river-74022
04/09/2025, 10:32 AMyaml
kind: Module
name: my-service
variables:
envVars:
LOG_LEVEL: debug
DATABASE_PASSWORD: ${var.database-password}
services:
- name: my-service
env: ${var.envVars} # References the entire envVars object
This allows you to reuse common values across your module configuration [Module variables]().
These approaches give you flexibility in how you manage environment variables across different environments and components in your Garden project.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
04/09/2025, 10:32 AM