Initial commit

This commit is contained in:
Conor.McManus 2019-04-09 16:54:28 +02:00
commit 6b0d8d0974
5 changed files with 178 additions and 0 deletions

130
.gitignore vendored Normal file
View file

@ -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 dont 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

9
Dockerfile Normal file
View file

@ -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

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# Terraform Atmosphere
> Docker build platform for Terraform

33
atmos.py Executable file
View file

@ -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)

4
shared-creds Normal file
View file

@ -0,0 +1,4 @@
[default]
AWS_SOMETHING
[ldm-preprod]