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. Read the tip 2 of this seris from our Teraclouds experts.

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, .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).
Want to read tip 3/3 “Terraform Workspaces, Direnv, Dotenv, and Mental Sanity”? Click here.
Teracloud is an AWS Advanced Consulting Partner specialized in Cloud Computing (AWS, Azure, GCP) best practices. We help SaaS of different industries around the world scale their business safely.
Contact our team at info@teracloud.io for an assessment. Let us handle migration, automation, deployment, performance, cost optimization and machine learning to make your business grow.
We make the cloud easy for you!