> ## Documentation Index
> Fetch the complete documentation index at: https://inframan.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment variables and secrets

> Set plain variables, shared env groups and secrets for your services, and see which value wins when they overlap.

A service's environment comes from five places: variables in `inframan.yaml`, env groups, secrets, connections, and variables Inframan sets for you. Secret values never go into your repository. They're stored in your own cloud's secret manager, and `inframan.yaml` refers to them by name.

## Plain variables

Set them under `env` in `inframan.yaml`:

```yaml inframan.yaml theme={null}
services:
  api:
    port: 8080
    env:
      LOG_LEVEL: info
      FEATURE_FLAGS: search,checkout
```

Plain variables are also passed to your build as Docker build arguments.

You can also edit a service's variables on its **Environment** tab in the console. Your edits are collected into one pull request that updates `inframan.yaml`. Merging it is the push that rolls the change out. While that pull request is open, further edits are blocked.

## Env groups

An **env group** is a named set of variables that several services share, such as the URLs of third-party APIs. Groups belong to an infrastructure.

1. Open the infrastructure and select the **Env groups** tab.
2. Create a group and add its variables.
3. Attach it to services by name:

```yaml inframan.yaml theme={null}
services:
  api:
    port: 8080
    envGroups: [shared-config, payments]
```

When two groups set the same variable, the group listed later wins.

## Secrets

Secrets are **infrastructure secrets**: values kept in your cloud account's secret manager, Secret Manager on Google Cloud or AWS Secrets Manager on AWS. Inframan stores only a reference to them.

1. Open the infrastructure and select the **Secrets** tab.
2. Add the secret with a name, such as `stripe-key`, and its value.
3. Reference it from a service, choosing the variable name:

```yaml inframan.yaml theme={null}
services:
  api:
    port: 8080
    secrets:
      STRIPE_KEY: stripe-key
```

At deploy time, Inframan reads the value from your secret manager and gives it to the service through a Kubernetes Secret. Updating an infrastructure secret rolls out every service that uses it.

The **Secrets** tab also holds **secret groups**: env groups whose values are secret, attached with `envGroups` like any other group.

> [!NOTE]
>
> Viewers can see secret names but never their values. A connected AI assistant can list secret names, but it can't create secrets or set values.

### Secrets at build time

A secret marked for builds is handed to Docker BuildKit as a secret mount, not as a build argument, so it never ends up in an image layer. In your `Dockerfile`, read it from the `inframan_build_secrets` secret:

```dockerfile Dockerfile theme={null}
RUN --mount=type=secret,id=inframan_build_secrets \
    NPM_TOKEN="$(grep '^NPM_TOKEN=' /run/secrets/inframan_build_secrets | cut -d= -f2- | base64 -d)" \
    npm ci
```

The file holds one `KEY=value` line per secret, and each value is base64-encoded so that newlines and special characters survive, so decode it as above. Build secrets are set on the service's **Environment** tab.

## Variables Inframan sets

Every web service receives:

| Variable | Value |
| - | - |
| `PORT` | The service's `port` |
| `INFRAMAN_APP_NAME` | The application's name |
| `INFRAMAN_SERVICE_NAME` | The service's name |
| `INFRAMAN_APP_SERVICE_NAME` | `<application>-<service>` |
| `INFRAMAN_NAMESPACE` | The application's namespace |
| `INFRAMAN_REVISION` | The running version, such as `api-v42` |
| `INFRAMAN_IMAGE_TAG` | The image tag being run |
| `INFRAMAN_ENVIRONMENT` | The infrastructure's tag, such as `nonprod` |
| `INFRAMAN_REGION` | The infrastructure's region |
| `INFRAMAN_EGRESS_IP` | The public IP address the service's outbound traffic comes from |
| `INFRAMAN_DOMAINS` | The service's domains, comma-separated |
| `INFRAMAN_RESOURCES_CPU`, `INFRAMAN_RESOURCES_MEMORY` | The service's CPU and memory limits, when set |
| `INFRAMAN_REPLICAS_MIN`, `INFRAMAN_REPLICAS_MAX` | The service's scaling range |
| `INFRAMAN_SERVICE_ACCOUNT` | The service's Google service account, when [workload identity](https://inframan.mintlify.site/secure/workload-identity.md) is on |

A variable is only set when Inframan has a value for it.

## Precedence

When the same variable name comes from more than one place, the first one in this list wins:

1. **Connections.** A plain variable with the same name is dropped.
2. **`env`** in `inframan.yaml`.
3. **Variables Inframan sets.**
4. **`secrets`** in `inframan.yaml`.
5. **Env groups**, with later groups winning over earlier ones, and a group's secret values winning over its plain ones.

> [!WARNING]
>
> A name set in both `env` and `secrets` takes the `env` value. Don't put a placeholder for a secret in `env`.

## Per environment

Override variables for production or non-production under `environments` in `inframan.yaml`. See [Environment overrides](https://inframan.mintlify.site/deploy/inframan-yaml.md#environment-overrides).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.