diff --git a/_templates/_template_alerting_profile.tf b/_templates/_template_alerting.tf similarity index 100% rename from _templates/_template_alerting_profile.tf rename to _templates/_template_alerting.tf diff --git a/environment.yaml b/environment.yaml new file mode 100644 index 00000000..7ffc9390 --- /dev/null +++ b/environment.yaml @@ -0,0 +1,12 @@ +EMEA_PROD: + - environments: [E2E,PROD] +EMEA_PREPROD: + - environments: [TEST,INT] +NA_PROD: + - environments: [E2E,PROD] +NA_PREPROD: + - environments: [TEST,INT] +CN_PROD: + - environments: [E2E,PROD] +CN_PREPROD: + - environments: [TEST,INT] \ No newline at end of file diff --git a/environments.yaml b/environments.yaml deleted file mode 100644 index a5b824b8..00000000 --- a/environments.yaml +++ /dev/null @@ -1,12 +0,0 @@ -EMEA_PROD: - - environments: ["E2E","PROD"] -EMEA_PREPROD: - - environments: ["TEST","INT"] -NA_PROD: - - environments: ["E2E","PROD"] -NA_PREPROD: - - environments: ["TEST","INT"] -CD_PROD: - - environments: ["E2E","PROD"] -CN_PREPROD: - - environments: ["TEST","INT"] \ No newline at end of file diff --git a/onboarding.py b/onboarding.py new file mode 100644 index 00000000..9aeed045 --- /dev/null +++ b/onboarding.py @@ -0,0 +1,47 @@ +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[0]) + 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()) + #print('./'+item+'/'+configoption+'/'+args.appname+'.tf') + with open('./'+item+'/'+configoption+'/'+args.appname+'.tf', 'w') as file: + file.write(data) + for envconfigoption in envconfigoptions: + for env in envs.get("environments"): + 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) + #print('./'+item+'/'+envconfigoption+'/'+args.appname+'_'+env+'.tf') + 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