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.
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:
Then we create two files, .env.dev and .env.prod. 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
Senior MLOps Engineer
Follow us on our social networks for more TeraTips