Is it possible to define array constants from Trellis to Bedrock?

The Goal:
To have an array constant on Bedrock:

define('ARRAY_OF_SECRETS', [
   'password_1',
   'password_2',
   ...
   'password_x',
]);

Questions:
Is it possible to:

  1. save these passwords in Trellis’ ansible vault
  2. “render” the passwords as environment variables
  3. “build” the PHP constant

I’ve tried adding variables in env inside wordpress_sites. However, it seems array is not supported.

Thanks!

It’s not possible unfortunately. We use .env which are supposed to be just environment variables which basically only supports strings (in reality it’s a bit more).

For anyone who facing the same issue:

$prefix = 'password_';

$index = 1;

while (! empty(Env::get($prefix . $index))) {
    $secrets[] = (string) Env::get($prefix . $index);
    $index++;
}

define('ARRAY_OF_SECRETS', $value);

Real life example: https://github.com/TypistTech/wp-password-argon-two-env/blob/0be822dfe9b615b7d9b10b43ac03376a90ef08f2/src/Converter.php#L47-L61

1 Like