Deploy Env Files with Terraform
An env file stores a KEY=VALUE configuration file in the Bahriya platform. Env files are scoped to your organisation, versioned with rotation history, and can be attached to projects and containers — their entries are injected into the container as environment variables via envFrom.
An env file stores a KEY=VALUE configuration file in the Bahriya platform. Env files are scoped to your organisation, versioned with rotation history, and can be attached to projects and containers — their entries are injected into the container as environment variables via envFrom.
Required fields
| Field | Type | Description |
|---|---|---|
handle | string | A unique identifier (DNS-1123 compliant: lowercase, alphanumeric, hyphens). |
name | string | A display name. |
content | string | The env file body — KEY=VALUE lines. Blank lines and # comments are allowed. |
Read-only fields
| Field | Type | Description |
|---|---|---|
entry_count | integer | Number of non-comment, non-blank entries parsed from content. |
currentversion | integer | The currently active version number. |
maxversions | integer | How many historic versions are retained (default 5). |
Example
resource "bahriya_env_file" "app_env" {
handle = "app-env"
name = "App Environment"
content = file("${path.module}/configs/app.env")
}where configs/app.env contains:
# Application environment
APP_MODE=production
LOG_LEVEL=info
FEATURE_X_ENABLED=trueAttach it to a project so it deploys to the project's regions:
resource "bahriya_project" "production" {
handle = "production"
name = "Production"
regions = ["helsinki-1", "falkenstein-1"]
}
resource "bahriya_project_env_file_attachment" "app_env" {
project_id = bahriya_project.production.id
handle = bahriya_env_file.app_env.handle
}Then mount it on a container — entries become environment variables on the running process:
resource "bahriya_container" "api" {
# ... other fields ...
env_files = [
{
handle = bahriya_env_file.app_env.handle
injectionmethod = "envFrom"
},
]
}injectionmethod is optional — envFrom is the only supported value today and is the default.
Rotation
To rotate env file contents, update the content field in your Terraform config and run terraform apply. The Bahriya API creates a new version and marks it current. Previous versions are retained for rollback.
Unlike file-mounted configs, env vars are injected at container start time. Containers must be redeployed (any update to the container, or a manual redeploy) to pick up new env values.
Importing an existing env file
terraform import bahriya_env_file.app_env <uuid>Pricing
Env files are billed at $0.02 per month while they exist in your organisation, plus $0.02 per region per month when attached to a project.