diff --git a/README.md b/README.md index a337ac7..6026ff3 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,25 @@ variable "workspace" { } ``` -This will make Terraform lookup AWS credentials from the `~/.aws/credentials` file using the workspace name as the stanza name. For example the credentials file would look like the shared-creds file in this repo. \ No newline at end of file +This will make Terraform lookup AWS credentials from the `~/.aws/credentials` file using the workspace name as the stanza name. For example the credentials file would look like the shared-creds file in this repo. + +## atmos -t + +Adding the `-t` 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: + +``` +DEFAULT_ACCESS_KEY_ID=id +DEFAULT_SECRET_ACCESS_KEY=key +``` + +All additional workspaces need to be prefixed in the same way: + +``` +DEV_ACCESS_KEY_ID=id +DEV_SECRET_ACCESS_KEY=key + +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. \ No newline at end of file diff --git a/atmos.py b/atmos.py index 47a90e1..c6042ff 100755 --- a/atmos.py +++ b/atmos.py @@ -7,7 +7,7 @@ def main(argv): parser = argparse.ArgumentParser(description='Control Terraform Workspaces.') g = parser.add_mutually_exclusive_group() g.add_argument("command", help="Send commands to terraform with workspace variable context", nargs='?', default=False) - parser.add_argument("-t", help="Template mode, gather shared-creds from environment variables", action='store_true', default=False) + parser.add_argument("-t", help="Template mode, gather shared-creds from environment variables (Dont use this flag if you dont want your ~/.aws/credentials replaced. This is for CI/CD", action='store_true', default=False) args, params = parser.parse_known_args() if args.command: determine_actions(args, params) @@ -42,7 +42,7 @@ def generate_creds(): contents = contents + "[{workspace}]\n".format(workspace=workspace) contents = contents + "access_key_id=" + os.environ.get(workspace.upper() + '_ACCESS_KEY_ID') + "\n" contents = contents + "secret_access_key=" + os.environ.get(workspace.upper() + '_SECRET_ACCESS_KEY') + "\n" - with open(os.path.expanduser('~/.aws/credentials.atmos'), 'w+') as f: + with open(os.path.expanduser('~/.aws/credentials'), 'w+') as f: f.write(contents) def get_valid_envs():