diff --git a/onboarding.py b/onboarding.py new file mode 100644 index 00000000..9ea9e2d9 --- /dev/null +++ b/onboarding.py @@ -0,0 +1,45 @@ +import yaml +from decouple import config +import argparse +import os +parser = argparse.ArgumentParser(description="Generate predefined Dynatrace configuration via Terraform", + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + +parser.add_argument("-A", "--appname", type=str,required=True, help="Your app_name") +parser.add_argument('-C', "--compassid", type=str,required=True, help="Your compass_id") +args = parser.parse_args() + +#Config options for onboarding. Will be extended with other configuration options in future +configoptions = ["management_zone"] +envconfigoptions = ["alerting","dashboard"] +def main(slo_path): + print("Generating tf files...") + if args.appname and args.compassid: + + with open('./environment.yaml') as file: + doc = yaml.safe_load(file) + + for item, doc in doc.items(): + envs = dict(doc[1]) + for configoption in configoptions: + with open('./_templates/_template_'+configoption+'.tf') as file: + data = file.read() + data = data.replace("", args.appname) + data = data.replace("", args.compassid.lower()) + with open('./'+item+'/'+configoption+'/'+args.appname+'.tf', 'w') as file: + file.write(data) + for envconfigoption in envconfigoptions: + for env in envs: + with open('./_templates/_template_'+envconfigoption+'.tf') as file: + data = file.read() + data = data.replace("", args.appname) + data = data.replace("", args.compassid.lower()) + data = data.replace("", env) + with open('./'+item+'/'+envconfigoption+'/'+args.appname+'_'+env+'.tf', 'w') as file: + file.write(data) + else: + print("ERROR: No appname/compassid specified") + + +if __name__ == "__main__": + main('') \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 00000000..f15c0304 --- /dev/null +++ b/readme.md @@ -0,0 +1,37 @@ +# Dynatrace onboarding repo / Terreform config +This repository holds the Dynatrace configuration for onboarding purposes + +# Prerequisites + +## Python packages +Before executing scripts, python requirements have to be satisfied. To do so, execute following command: + pip install -r requirements.txt + +# Usage + + 1. Clone template: + git clone --branch template ssh://git@git.bmwgroup.net:7999/opapm/coco_apm_terraform_onboarding.git + 2. Create branch: + git checkout -b CD_ + 3.Install python dependencies: + pip install -r requirements.txt + 4.Run onboarding script: + python ./onboarding.py -A CD_ -C + 5. Review created files: + git status + 6. Commit your changes: + git add + + git commit -m " - Add initial configuration of application to Dynatrace" + + git push -u origin CD_ + 7. Create pull request from CD_ to master +# Files + +## onboarding.py + +This scripts generates predefined configuration basing on your app_name and compass ids + +## requirements.txt + +File containing required python packages diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..06c938c3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +python-decouple +pyyaml +argparse \ No newline at end of file