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:
[includeIf "gitdir:~/client_1/"]
path = ~/client_1/.gitconfig
[includeIf "gitdir:~/client_2/"]
path = ~/client_2/.gitconfig
[user]
name = Name1
email = name@client_1_email.com
[init]
defaultBranch = master
[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:
Host server1
HostName neon_kimchi.com
User Name1
IdentityFile ~/client_1/.ssh/id_ed25519
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:
[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
[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:
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:
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:
export AWS_ACCESS_KEY_ID=AKXXXXXX
export AWS_SECRET_ACCESS_KEY=V12xxxxxxx
export AWS_DEFAULT_REGION=eu-west-1
export AWS_ACCESS_KEY_ID=KAXXXXXX
export AWS_SECRET_ACCESS_KEY=C8xxxxxxx
export AWS_DEFAULT_REGION=us-east-1
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!