how can I reference an environment variable in gar...
# 🤖|ask-kapa
f
@microscopic-river-74022 how can I reference an environment variable in garden.yml?
m
Please stand by @faint-minister-59136 as I search the knowledge base. I normally take about 15 seconds or so. :wave:
---------------------- In Garden, you can reference environment variables in your garden.yml files using template strings. There are several ways to do this depending on your needs: ## Using Project Variables You can define variables in your project configuration and reference them in your actions or modules:
Copy code
yaml
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:
Copy code
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:
Copy code
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:
Copy code
yaml
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: ----------------------
message has been deleted
3 Views