65 lines
2.6 KiB
Python
65 lines
2.6 KiB
Python
#!/usr/bin/env python
|
|
""" Load Dynatrace Configuration Script.
|
|
This program is free software: you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
version.
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
|
|
__author__ = "Arnautovic Arnel"
|
|
__contact__ = "Arnel.Arnautovic@nttdata.com"
|
|
__copyright__ = "Copyright 2021, NTT DATA"
|
|
__credits__ = ["Ermis Wieger", "René Forstner"]
|
|
__date__ = "2021/11/29"
|
|
__deprecated__ = False
|
|
__license__ = "GPLv3"
|
|
__maintainer__ = "developer"
|
|
__status__ = "Prototype"
|
|
__version__ = "0.0.1"
|
|
|
|
# [AA 2021.11.29] Import modules
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
import shutil
|
|
from dotenv import load_dotenv
|
|
|
|
# [AA 2021.11.29] Load enviroment file
|
|
load_dotenv()
|
|
|
|
# [AA 2021.11.29] Arguments passed
|
|
if(len(sys.argv) == 1):
|
|
# , "NAPROD", "EUPREPROD", "NAPREPROD", "CNPROD", "CNPREPROD"]:
|
|
for i in ["EUPROD"]:
|
|
os.environ['DYNATRACE_ENV_URL'] = str(os.getenv(i + "_ENV_URL"))
|
|
os.environ['DYNATRACE_API_TOKEN'] = str(os.getenv(i + "_API_TOKEN"))
|
|
os.environ['DYNATRACE_TARGET_FOLDER'] = str(
|
|
"./configuration/" + time.strftime("%Y%m%d-%H%M%S") + "_" + i + "_CONFIGURATION")
|
|
subprocess.run(
|
|
[".\\bin\\terraform-provider-dynatrace_v1.8.4.exe", "export", "dynatrace_management_zone"])
|
|
# Cpy module
|
|
|
|
# Cpy conifiguration
|
|
shutil.copyfile(".\\templates\\configuration.tf",
|
|
os.environ['DYNATRACE_TARGET_FOLDER'] + "\\configuration.tf")
|
|
|
|
# iterate trought each folder in targetfolder
|
|
for filename in os.listdir(os.environ['DYNATRACE_TARGET_FOLDER']):
|
|
f = os.path.join(os.environ['DYNATRACE_TARGET_FOLDER'], filename)
|
|
# checking if it is a file
|
|
if os.path.isdir(f):
|
|
print(f)
|
|
with open(os.environ['DYNATRACE_TARGET_FOLDER'] + "\\configuration.tf", "a") as myfile:
|
|
myfile.writelines("\n" + "module \"" + filename +
|
|
"\" { source = \"./" + filename + "\"}")
|
|
shutil.copyfile(".\\templates\\module.tf", f + "\\module.tf")
|
|
else:
|
|
print("Usage example: ")
|
|
print("python .\exportConfig.py")
|