Skip to content

How to Manage Multiple Development Environments

Managing diverse projects or clients requires smoothly switching between their distinct development environments. One possible solution could involve creating individual user sessions for each project / client and switching between environments by logging out and logging in the other session. Another approach could be setting up dynamic development configuration files based on your folder structure.

Multiple GIT Identities

Use a primary .gitconfig in the home folder, directing to other .gitconfig files based on your location within the folder structure.

Folder Structure and Config Files Example:

.
├── .gitconfig
├── client_1
   └── .gitconfig
└── client_2
    └── .gitconfig
~/.gitconfig
[includeIf "gitdir:~/client_1/"]
    path = ~/client_1/.gitconfig

[includeIf "gitdir:~/client_2/"]
    path = ~/client_2/.gitconfig
~/client_1/.gitconfig
[user]
 name = Name1
 email = name@client_1_email.com
[init]
 defaultBranch = master  
~/client_2/.gitconfig
[user]
 name = Name2
 email = name@client_2_email.com
[init]
 defaultBranch = main

Multiple SSH Configurations

Similar to the approach above, maintain a ~/.ssh/config file directing to the .ssh configurations of different projects / clients.

Folder Structure and Config Files Example:

.
├── .ssh/config
├── client_1
   └── /.ssh/config
└── client_2
    └── /.ssh/config
~/.ssh/config
Include ~/client_1/.ssh/config
Include ~/client_2/.ssh/config
~/client_1/.ssh/config
Host server1
  HostName neon_kimchi.com
  User Name1
  IdentityFile ~/client_1/.ssh/id_ed25519
~/client_2/.ssh/config
Host server2
  HostName zima_blue.com
  User Name2
  IdentityFile ~/client_2/.ssh/id_ed25519

Note

Ensure that you apply chmod 700 to the .ssh folder and chmod 600 to the private keys.

Multiple AWS CLI Identities

To manage different AWS accounts with AWS CLI, one solution is to create multiple AWS profiles in the credentials file. This can be done using the aws configure command or by directly modifying the credential files:

~/.aws/credentials
[default]
aws_access_key_id = DEFAULT_ACCESS_KEY
aws_secret_access_key = DEFAULT_SECRET_KEY

[client_1]
aws_access_key_id = CLIENT1_ACCESS_KEY
aws_secret_access_key = CLIENT1_SECRET_KEY

[client_2]
aws_access_key_id = CLIENT2_ACCESS_KEY
aws_secret_access_key = CLIENT2_SECRET_KEY
~/.aws/config
[default]
region = eu-west-1

[profile client_1]
region = us-east-1

[profile client_2]
region = us-east-2

To use a specific profile with AWS CLI commands:

aws s3 --profile=client1 ls s3://client_1_bucket
aws s3 --profile=client2 ls s3://client_2_bucket

Note

Be careful when setting up multiple AWS credential configurations. Some methods take precedence over others. You can find the list here: AWS Auth Precedence List. For instance, environment variables take precedence over credential files.

Remember to refer to the official AWS documentation for further guidance on managing AWS profiles and configurations: AWS CLI Official guide

Managing Multiple AWS Identities in Terraform Projects

Option 1: Using AWS Profiles

Declare the AWS profile in your Terraform project files:

~/client_1/make_me_billions_project/terraform/providers.tf
provider "aws" {
  profile= "client_1"
}
~/client_2/feet_fetish_project/terraform/providers.tf
provider "aws" {
  profile= "client_2"
}

Option 2: Utilizing Environment Variables

Utilize direnv (Direnv Github) for dynamic environment variable loading and unloading based on your directory:

Quick Setup and Folder Structure:

sudo apt install direnv
.
├── client_1
   └── .envrc
└── client_2
    └── .envrc
~/client_1/.envrc
export AWS_ACCESS_KEY_ID=AKXXXXXX
export AWS_SECRET_ACCESS_KEY=V12xxxxxxx
export AWS_DEFAULT_REGION=eu-west-1
~/client_2/.envrc
export AWS_ACCESS_KEY_ID=KAXXXXXX
export AWS_SECRET_ACCESS_KEY=C8xxxxxxx
export AWS_DEFAULT_REGION=us-east-1
direnv allow ~/client_1/
direnv allow ~/client_2/

Upon entering a client folder, the respective environment variables will load automatically:

direnv: loading ~/client_1/.envrc
direnv: export +AWS_DEFAULT_REGION ~AWS_ACCESS_KEY_ID ~AWS_SECRET_ACCESS_KEY

The environment variables unload when you exit the folder structure. No need to add profiles or credentials in the Terraform provider file.

PS: Kudos to the Direnv team for this awesome tool!