Adding script to template
parent
d725250bf7
commit
f313af3846
|
|
@ -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("<APPNAME>", args.appname)
|
||||
data = data.replace("<COMPASSID>", 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("<APPNAME>", args.appname)
|
||||
data = data.replace("<COMPASSID>", args.compassid.lower())
|
||||
data = data.replace("<APPENV>", 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('')
|
||||
|
|
@ -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_<appname>
|
||||
3.Install python dependencies:
|
||||
pip install -r requirements.txt
|
||||
4.Run onboarding script:
|
||||
python ./onboarding.py -A CD_<app_name> -C <compass_id>
|
||||
5. Review created files:
|
||||
git status
|
||||
6. Commit your changes:
|
||||
git add <changes>
|
||||
|
||||
git commit -m "<OPMAAS-XXX> - Add initial configuration of application <app_name> to Dynatrace"
|
||||
|
||||
git push -u origin CD_<app_name>
|
||||
7. Create pull request from CD_<app_name> 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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
python-decouple
|
||||
pyyaml
|
||||
argparse
|
||||
Loading…
Reference in New Issue