Advanced Direnv for Devops

Now you are using Direnv to manage your workspaces (see THIS), but you stumble upon a difficulty, maybe motivated (like me) by Terraform workspaces.

You have a single codebase for a project, but this codebase needs to be deployed to different environments. Now, we can no longer have a .envrc file in the project's folder, because the environment should be different depending on where we want to deploy. So, how do we solve this? Direnv to the rescue, again.

Using .env's

Direnv has a directive called dotenv, which can be used to load a set of variables dynamically. So in our .direnv file, we can write:

dotenv .env.${ENVIRONMENT}

Then we create two files, and So, each time we enter the directory, the filename of the environment to load is built with the variable $ENVIRONMENT (dev or prod in our case).

Do not miss next week the last tip of this series of Teratips

Carlos Barroso

Senior MLOps Engineer

#Teracloud #TeraTips #aws #awslatam #DevOps #Direnv #cloudtools #TeraTipseries #Kubernetes #security #Terraform

Follow us on our social networks for more TeraTips

Entradas recientes
Buscar por tags