Fernando Torres
Fernando Torres

Reputation: 470

Laravel Enviroment Variables are not working within Google Cloud Run

I've deployed too many times Laravel projects up to Cloud Run successfully, but right now

It looks like Cloud Run is unable to read Enviroment Variables (which i've specified already in the Variables&Secrets section within Cloud Run instance).

enter image description here

I'm using Laravel 8. For testing purposes (and make sure Cloud Run it's reading env variables), i've added a simple route in the api.php section like belows:

Route::get('/test-env', function () {
    echo 'debuggeando<br>';
   dd(config('variables.test_env'));
});

Into my config/variables.php i've the follows:

<?php
return [
    'test_env' => env('TEST_ENV', 'no se encontro la variable')
];

And this is my final result:

enter image description here

What do am I doing wrong? Why Cloud Run is unable to read the enviroment variables from Laravel?

Upvotes: 0

Views: 1184

Answers (1)

Martin Zeitler
Martin Zeitler

Reputation: 76649

You can only make Laravel pick up envirnmental variables, but not the other way around.

config(['test_env' => getenv('TEST_ENV')]);

Running php artisan config:clear & php artisan config:cache might be required. Another option might be to generate a fresh .env file during the deployment, which merely translates to: already defining the value, before it can be cached.

Upvotes: 1

Related Questions