Atmos will use its own credentials file
This commit is contained in:
parent
6bcd68e410
commit
dc5ba48990
2 changed files with 7 additions and 4 deletions
|
|
@ -36,6 +36,7 @@ To get the most out of Terraform workspaces it is recommended that the AWS provi
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "${var.region}"
|
region = "${var.region}"
|
||||||
profile = "${var.workspace}"
|
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
|
## 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
|
DEFAULT_ACCESS_KEY_ID=id
|
||||||
|
|
@ -68,7 +69,7 @@ QA_ACCESS_KEY_ID=id
|
||||||
QA_SECRET_ACCESS_KEY=key
|
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
|
# atmos -m
|
||||||
|
|
||||||
|
|
|
||||||
6
atmos.py
6
atmos.py
|
|
@ -14,7 +14,9 @@ def main(argv):
|
||||||
determine_actions(args, params)
|
determine_actions(args, params)
|
||||||
|
|
||||||
def determine_actions(args, params):
|
def determine_actions(args, params):
|
||||||
|
aws_creds_file = "$HOME/.aws/credentials"
|
||||||
if (is_git_directory()) and not (args.m):
|
if (is_git_directory()) and not (args.m):
|
||||||
|
aws_creds_file = aws_creds_file + "-atmos"
|
||||||
workspace_manager()
|
workspace_manager()
|
||||||
|
|
||||||
workspace = get_env()
|
workspace = get_env()
|
||||||
|
|
@ -22,7 +24,7 @@ def determine_actions(args, params):
|
||||||
cmd = 'terraform {args}'.format(args=args.command)
|
cmd = 'terraform {args}'.format(args=args.command)
|
||||||
|
|
||||||
if (args.command in env_actions) and not (args.p): # Append with env context
|
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
|
for param in params: # Pass terraform params directly through
|
||||||
cmd = cmd + ' ' + param
|
cmd = cmd + ' ' + param
|
||||||
|
|
@ -62,7 +64,7 @@ def generate_creds():
|
||||||
contents = contents + "[{workspace}]\n".format(workspace=workspace)
|
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_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"
|
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)
|
f.write(contents)
|
||||||
|
|
||||||
def get_valid_envs():
|
def get_valid_envs():
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue