runr_binding_attachment (Resource)
Attaches a runr_binding to a project: the binding's connection details reach the project's functions as environment variables (with env_prefix in front, e.g. ORDERS_DATABASE_URL). Attaching, changing the prefix or the credentials and detaching roll the running service; nothing needs to be redeployed.
A kv, object or postgres binding can be attached to projects of its region; external bindings to any project. With environment the binding is attached to one environment of the project instead of its own workload (it must be in the region the environment runs in); bindings are never inherited, and a binding is attached to at most one environment of a project. Needs env.edit on the project and bindings.manage. Import with <project name or id>/<binding name or id> or <project name or id>/<environment>/<binding name or id>.
Example Usage#
# orders-api gets ORDERS_DATABASE_URL, ORDERS_PGHOST, … and REDIS_URL, KV_PREFIX.
resource "runr_binding_attachment" "orders_db" {
project_id = runr_project.api.id
binding_id = runr_binding.orders_db.id
env_prefix = "ORDERS_"
}
resource "runr_binding_attachment" "cache" {
project_id = runr_project.api.id
binding_id = runr_binding.cache.id
}
output "binding_variables" {
value = concat(runr_binding_attachment.orders_db.env_names, runr_binding_attachment.cache.env_names)
}
# staging gets a database of its own (bindings are never inherited), with a Postgres user of the
# attachment's own from the OpenBao of its region.
resource "runr_binding_attachment" "staging_db" {
project_id = runr_project.api.id
environment = runr_environment.staging.name
binding_id = runr_binding.staging_db.id
env_prefix = "ORDERS_"
credentials = "dynamic"
}
Schema#
Required#
binding_id(String) Binding id (runr_binding.<name>.id).project_id(String) Project id.
Optional#
credentials(String)static(the binding's own user; the default) ordynamic: a Postgres user of the attachment's own from the OpenBao of its region, renewed by RunR (a readypostgresbinding; the region runs OpenBao and External Secrets Operator). Changed in place. Left out, the attachment keeps its credentials.env_prefix(String) Prefix of the variable names: upper case letters, digits and_, starting with a letter and ending with_(default: none). Changing it updates the attachment in place.environment(String) Environment of the project the binding is attached to (runr_environment.<name>.nameor its id): its variables go into the environment's bindings Secret and only its pods may reach the binding. Left out (orproduction): the project's own workload. Changing it attaches the binding anew.
Read-Only#
env_names(List of String) The variables the project gets from this attachment.id(String) Attachment id.
Import#
Import is supported using the following syntax:
The terraform import command can be used, for example:
# <project name or id>/<binding name or id>
terraform import runr_binding_attachment.orders_db orders-api/orders-db
# An attachment of an environment: <project name or id>/<environment>/<binding name or id>
terraform import runr_binding_attachment.staging_db orders-api/staging/orders-db-staging