master
rforstner 2022-03-02 16:16:30 +01:00
commit 76dae3608e
3 changed files with 274 additions and 0 deletions

193
.gitignore vendored Normal file
View File

@ -0,0 +1,193 @@
.env
.vscode
output/
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# Crash log files
crash.log
crash.*.log
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json
# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json
# Include override files you do wish to add to version control using negated pattern
# !example_override.tf
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
# Ignore CLI configuration files
.terraformrc
terraform.rc
# 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/
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
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .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
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# 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/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

79
copyData.py Normal file
View File

@ -0,0 +1,79 @@
import sys
import os
import shutil
from itertools import islice
def copy(src, dst, rename):
try:
shutil.copyfile(src, dst)
if rename is False:
print("[DEBUG]", "Copied file from %s to %s." % (src, dst))
else:
print("[DEBUG]", "Renamed file from %s to %s." % (src, dst))
except shutil.SameFileError:
print("Source and destination represents the same file.")
except IsADirectoryError:
print("Destination is a directory.")
except PermissionError:
print("Permission denied.")
except Exception as e:
print(e)
print("Error occured while copying file.")
p = '.\configuration\slo\\'
for file in os.listdir(p):
fn_content = file.split(".")
vars = {}
with open(os.path.join(p,file)) as f:
i = 0
firstLine = f.readline()
meta = firstLine.split()
for line in f:
multiline = ""
#check for key value pair
if " = " in line:
try:
if "<<-EOT" in line:
multiline = "<<-EOT\n"
skipped = islice(f,i,None)
for i, l in enumerate(skipped):
if "EOT" not in l:
multiline = multiline + l
else:
multiline = multiline + l
break
name,var = line.partition(" = ")[::2]
var.strip()
if multiline != "":
var = multiline
#remove spaces and "#" as this is used for optional fields
vars['"{' + name.strip().lstrip("#").strip() + '}"'] = var
vars["{ResourceName}"] = meta[2].replace('"','')
except Exception as e:
print(e)
i = i + 1
copy('./templates/service-level-objective.tf','./output/slo/service-level-objective.tf',False)
os.rename('.\output\slo\service-level-objective.tf','./output/slo/' + meta[2].replace('"','') + '.tf')
with open('./output/slo/' + meta[2].replace('"','') + '.tf') as tf:
data = tf.read()
for key,var in vars.items():
#print(key,var)
data = data.replace(key, var)
with open('./output/slo/' + meta[2].replace('"','') + '.tf','w+') as tf:
tf.write(data)
tf_command = "terraform.exe import module." + meta[2].replace('"','') + ".dynatrace_slo.main " + fn_content[1]
print(tf_command)

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
python-dotenv
pyhcl