I am writing a helm template for external secrets.
The secrets are in AWS secrets manager, and they're prefixed with "dev" or "prod".
Namespaces are used to differentiate environments, but there are many more than "dev" or "prod" -- "prod" and "prod-phi" should use "prod" secrets, while everything else should use "dev" secrets.
To accomplish that, I have a pretty long expression, which you can see prefixing a secret name here:
- secretKey: RdsDataUsername
remoteRef:
key: {{ or (eq .Release.Namespace "prod") (eq .Release.Namespace "prod-phi") | ternary "prod" "dev" }}/rds/data/primary
property: username
I am repeating that expression "{{ or (eq .Release.Namespace "prod") (eq .Release.Namespace "prod-phi") | ternary "prod" "dev" }}
" many times throughout this file, and it's affecting readability.
Is there a way to set a variable one time in the file using this expression, then reference that instead?
Something like:
variables:
prefix: {{ or (eq .Release.Namespace "prod") (eq .Release.Namespace "prod-phi") | ternary "prod" "dev" }}
spec:
data:
- secretKey: RdsDataUsername
remoteRef:
key: {{ $prefix }}/rds/data/primary
property: username