diff --git a/README.md b/README.md index 68e8663..8559cea 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ To get the most out of Terraform workspaces it is recommended that the AWS provi provider "aws" { region = "${var.region}" profile = "${var.workspace}" + shared_credentials_file = ${var.shared_credentials_file} } ``` @@ -51,7 +52,7 @@ This will make Terraform lookup AWS credentials from the `~/.aws/credentials` fi ## atmos -e -Adding the `-e` flag to atmos will make it generate a new `~/.aws/credentials` file from environment variables. You must first include the `default` access key ID & secret access key like this: +Adding the `-e` flag to atmos will make it generate a new `~/.aws/credentials-atmos` file from environment variables. You must first include the `default` access key ID & secret access key like this: ``` DEFAULT_ACCESS_KEY_ID=id @@ -68,7 +69,7 @@ QA_ACCESS_KEY_ID=id QA_SECRET_ACCESS_KEY=key ``` -Note: Atmos will override your default credentials file as this functionality is for use in a docker container or in situations where you would rather use variables. +This requires a `shared_credentials_file` variable on the top level. To support standard Terraform workflows its recommened to default this to the default shared credentials file location `$HOME/.aws/credentials`. Atmos will then handle the overriding safely in the background # atmos -m diff --git a/atmos.py b/atmos.py index cb24ea2..37359d7 100755 --- a/atmos.py +++ b/atmos.py @@ -14,7 +14,9 @@ def main(argv): determine_actions(args, params) def determine_actions(args, params): + aws_creds_file = "$HOME/.aws/credentials" if (is_git_directory()) and not (args.m): + aws_creds_file = aws_creds_file + "-atmos" workspace_manager() workspace = get_env() @@ -22,7 +24,7 @@ def determine_actions(args, params): cmd = 'terraform {args}'.format(args=args.command) if (args.command in env_actions) and not (args.p): # Append with env context - cmd = cmd + ' -var-file=vars/{env}.tfvars -var "workspace={env}"'.format(env=workspace) + cmd = cmd + ' -var-file=vars/{env}.tfvars -var "workspace={env}" -var "shared_credentials_file={aws_creds_file}"'.format(env=workspace, aws_creds_file=aws_creds_file) for param in params: # Pass terraform params directly through cmd = cmd + ' ' + param @@ -62,7 +64,7 @@ def generate_creds(): contents = contents + "[{workspace}]\n".format(workspace=workspace) contents = contents + "aws_access_key_id=" + os.environ.get(workspace.upper() + '_ACCESS_KEY_ID') + "\n" contents = contents + "aws_secret_access_key=" + os.environ.get(workspace.upper() + '_SECRET_ACCESS_KEY') + "\n" - with open(os.path.expanduser('~/.aws/credentials'), 'w+') as f: + with open(os.path.expanduser('~/.aws/credentials-atmos'), 'w+') as f: f.write(contents) def get_valid_envs():