commit 6b0d8d0974e1e76f65b05e28f89ec18c0be8e910 Author: Conor.McManus Date: Tue Apr 9 16:54:28 2019 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5568589 --- /dev/null +++ b/.gitignore @@ -0,0 +1,130 @@ + +# Created by https://www.gitignore.io/api/python +# Edit at https://www.gitignore.io/?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don’t work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# End of https://www.gitignore.io/api/python diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e9f0de0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine + +RUN apk add python3 +RUN wget -O /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip +RUN unzip /tmp/terraform.zip +RUN mv terraform /usr/bin/ + +COPY shared-creds /root/.aws/credentials +COPY atmos.py /usr/bin/atmos diff --git a/README.md b/README.md new file mode 100644 index 0000000..22510c9 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Terraform Atmosphere +> Docker build platform for Terraform \ No newline at end of file diff --git a/atmos.py b/atmos.py new file mode 100755 index 0000000..d1d1471 --- /dev/null +++ b/atmos.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess +import sys + +def main(argv): + parser = argparse.ArgumentParser(description='Control Terraform Workspaces.') + parser.add_argument("command", help="Send commands to terraform", default=False) + parser.add_argument("-auto", help="Flag to skip waiting for user input", action="store_true") + args = parser.parse_args() + determine_actions(args) + +def determine_actions(args): + if args.auto: + args.command = args.command + " -auto-approve" + valid_actions = ["plan", "apply", "destroy"] + if args.command in valid_actions: + print('Terraform {args} using env vars in {env}'.format(args=args.command, env=get_env())) + print(subprocess.getoutput('terraform {args} -var-file=vars/{env}.tfvars'.format(args=args.command, env=get_env()))) + else: + print(subprocess.getoutput('terraform {args}'.format(args=args.command))) + +def get_env(): + valid_envs = ["dev","preprod","emea","apac"] + tf_env = subprocess.getoutput('cat .terraform/environment') + if str(tf_env) in valid_envs: + return(tf_env) + else: + return("qa") + +if __name__ == "__main__": + main(sys.argv) \ No newline at end of file diff --git a/shared-creds b/shared-creds new file mode 100644 index 0000000..9452af7 --- /dev/null +++ b/shared-creds @@ -0,0 +1,4 @@ +[default] +AWS_SOMETHING + +[ldm-preprod] \ No newline at end of file