env

package
v0.40.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 7 Imported by: 0

README

Environment Variables Backend

The env backend enables confd to retrieve configuration data from environment variables. This is the simplest backend, requiring no external services or authentication.

Configuration

No configuration is required. The env backend reads directly from the process environment.

Key Mapping

Environment variable names are mapped to confd keys using the following transformation:

confd key Environment variable
/myapp/database/url MYAPP_DATABASE_URL
/myapp/database/user MYAPP_DATABASE_USER
/config/api/key CONFIG_API_KEY

The transformation rules:

  1. Remove the leading /
  2. Replace / with _
  3. Convert to uppercase

When confd retrieves values, it reverses this transformation to present keys in the standard /path/format.

Options

The env backend has no backend-specific flags.

Basic Example

Set environment variables:

export MYAPP_DATABASE_URL=db.example.com
export MYAPP_DATABASE_USER=admin
export MYAPP_DATABASE_PASSWORD=secret123

Create template resource (/etc/confd/conf.d/myapp.toml):

[template]
src = "myapp.conf.tmpl"
dest = "/etc/myapp/config.conf"
keys = [
  "/myapp/database",
]

Create template (/etc/confd/templates/myapp.conf.tmpl):

[database]
url = {{getv "/myapp/database/url"}}
user = {{getv "/myapp/database/user"}}
password = {{getv "/myapp/database/password"}}

Run confd:

confd env --onetime

Advanced Example

Using with Docker or Kubernetes:

Docker:

docker run -e MYAPP_DATABASE_URL=db.example.com \
           -e MYAPP_DATABASE_USER=admin \
           -v /etc/confd:/etc/confd \
           myapp-with-confd

Kubernetes ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp-config
data:
  MYAPP_DATABASE_URL: "db.example.com"
  MYAPP_DATABASE_USER: "admin"
---
apiVersion: v1
kind: Pod
metadata:
  name: myapp
spec:
  containers:
  - name: myapp
    envFrom:
    - configMapRef:
        name: myapp-config

Kubernetes Secrets:

apiVersion: v1
kind: Secret
metadata:
  name: myapp-secrets
type: Opaque
stringData:
  MYAPP_DATABASE_PASSWORD: "secret123"
---
apiVersion: v1
kind: Pod
metadata:
  name: myapp
spec:
  containers:
  - name: myapp
    envFrom:
    - secretRef:
        name: myapp-secrets

Watch Mode Support

Watch mode is not supported for the env backend. Environment variables are only read at startup or when using interval mode.

For periodic updates:

confd env --interval 60

Per-Resource Backend Configuration

Instead of using the global backend, individual template resources can specify their own env backend configuration. This allows mixing backends within a single confd instance.

Add a [backend] section to your template resource file:

[template]
src = "myapp.conf.tmpl"
dest = "/etc/myapp/config.conf"
keys = [
  "/myapp/database",
]

[backend]
backend = "env"

Available backend options:

  • backend - Must be "env"

The env backend has no additional configuration options.

Use Cases

The env backend is ideal for:

  • 12-factor applications following environment-based configuration
  • Container deployments where config is injected via environment
  • Local development with simple configuration needs
  • CI/CD pipelines where secrets are passed as environment variables
  • Serverless functions that receive configuration via environment

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct{}

Client provides a shell for the env client

func NewEnvClient

func NewEnvClient() (*Client, error)

NewEnvClient returns a new client

func (*Client) Close

func (c *Client) Close() error

Close is a no-op for this backend.

func (*Client) GetValues

func (c *Client) GetValues(ctx context.Context, keys []string) (map[string]string, error)

GetValues queries the environment for keys

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck verifies the backend is healthy. Environment variables are always available, so this always returns nil.

func (*Client) HealthCheckDetailed

func (c *Client) HealthCheckDetailed(ctx context.Context) (*types.HealthResult, error)

HealthCheckDetailed provides detailed health information for the environment backend.

func (*Client) WatchPrefix

func (c *Client) WatchPrefix(ctx context.Context, prefix string, keys []string, waitIndex uint64, stopChan chan bool) (uint64, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL