Second init.
parent
6b38243d43
commit
34dc324a3d
|
|
@ -1,5 +1,6 @@
|
|||
bin/
|
||||
output/
|
||||
outboard/
|
||||
export/
|
||||
.env
|
||||
.terraform.lock.hcl
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"Modules":[{"Key":"m2","Source":"./output/20220117-132316_EMEA_PROD/credentials","Dir":""},{"Key":"","Source":"","Dir":"."},{"Key":"dynatrace_custom_service","Source":"./output/20220117-132316_EMEA_PROD/custom_services","Dir":""},{"Key":"dynatrace_service_naming","Source":"./output/20220117-132316_EMEA_PROD/naming/services","Dir":""},{"Key":"m1","Source":"./output/20220117-132316_EMEA_PROD/anomalies","Dir":""}]}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
from operator import rshift
|
||||
import os
|
||||
import shutil
|
||||
from glob import glob
|
||||
import hcl
|
||||
|
||||
|
||||
# [AA 2022.12.20] Copy file
|
||||
def copyFile(src, dst):
|
||||
try:
|
||||
shutil.copyfile(src, dst)
|
||||
except:
|
||||
print("[DEBUG]", "Copy error for %s ." % dst)
|
||||
|
||||
# [AA 2021.12.20] Creating directory method
|
||||
def createDir(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError:
|
||||
print("[DEBUG]", "Directory %s already exists." % path)
|
||||
else:
|
||||
print("[DEBUG]", "Successfully created the directory %s." % path)
|
||||
|
||||
# [AA 2021.12.20] Fill dictionary
|
||||
def readFile(path):
|
||||
with open(path, 'r', encoding='utf8') as cfg:
|
||||
|
||||
# [AA 2021.12.01] Load the content of the particular resource file in eg: management_zones
|
||||
obj = hcl.load(cfg)
|
||||
|
||||
# [AA, EW 2021.12.01] Store resource type and resource name of that file into a dictionary
|
||||
key = list(obj['resource'].keys())[0]
|
||||
val = list(obj['resource'][key].keys())[0]
|
||||
return key, val
|
||||
|
||||
|
||||
# [AA, EW 2022.01.17] Load all resources and add them to a dictionary
|
||||
def createFolderStructure():
|
||||
resourcePaths = {}
|
||||
management_zones = [os.path.normpath(f).replace('\\', '/') for f in glob(sourceFolder + "**/management_zones/**.tf", recursive=True)]
|
||||
for index, file in enumerate(management_zones):
|
||||
environment = ("./"+os.path.dirname(os.path.dirname(file))).replace(sourceFolder, "")
|
||||
splittedFilename = os.path.basename(file).split(".")
|
||||
|
||||
# [AA 2022.01.20] Filter out module.tf and main.tf
|
||||
if len(splittedFilename) == 5:
|
||||
resourceID = splittedFilename[1]
|
||||
moduleName, resourceName = readFile(file)
|
||||
|
||||
# [AA 2022.01.20] Create direcotires and copy associated files
|
||||
resourcePath = os.path.join(outputFolder + environment + "/", resourceName)
|
||||
if not resourcePath in resourcePaths.keys():
|
||||
resourcePaths.setdefault("resourcePaths", [])
|
||||
resourcePaths["resourcePaths"].append(resourcePath)
|
||||
|
||||
createDir(resourcePath)
|
||||
copyFile(file, os.path.join(resourcePath, os.path.basename(file)))
|
||||
return resourcePaths
|
||||
|
||||
def filterCondition(filename):
|
||||
|
||||
return '/dashboards/' in filename or '/alerting_profiles/' in filename;
|
||||
#'/dashboards/' in filename or
|
||||
|
||||
def fillOtherResources(resourcePaths):
|
||||
otherResources = [os.path.normpath(f).replace('\\', '/') for f in glob(sourceFolder + "**/**.tf", recursive=True)]
|
||||
otherResources_iterator= filter(filterCondition, otherResources)
|
||||
otherResource_filterd=list(otherResources_iterator)
|
||||
for resourcePath in resourcePaths["resourcePaths"]:
|
||||
for element in otherResource_filterd:
|
||||
elementName = os.path.basename(element).split(".")[0].split(" ")[0]
|
||||
resourceName = os.path.basename(resourcePath)
|
||||
if elementName == resourceName:
|
||||
copyFile("./" + element, resourcePath + "/" + os.path.basename(element))
|
||||
print("[DEBUG]", "File %s copied to %s." % (os.path.basename(element), resourcePath))
|
||||
|
||||
|
||||
# [AA, EW 2022.01.20] Set global variables
|
||||
global cwd, targetFolder, templatesFolder, outputFolder, sourceFolder
|
||||
cwd = os.getcwd()
|
||||
sourceFolder = "./export/"
|
||||
outputFolder = "./output/"
|
||||
|
||||
if __name__ == "__main__":
|
||||
# [AA, EW 2022.01.20]
|
||||
fillOtherResources(createFolderStructure())
|
||||
18
main.tf
18
main.tf
|
|
@ -1,18 +0,0 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
dynatrace = {
|
||||
version = "1.9.1"
|
||||
source = "dynatrace-oss/dynatrace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# module "configDir" {
|
||||
# source = "git::https://github.com/arnauagithub/DynatraceTerraformConfiguration.git?ref=20211130-151123"
|
||||
# }
|
||||
|
||||
|
||||
module "m1" { source = "./output/20220117-132316_EMEA_PROD/anomalies" }
|
||||
module "m2" { source = "./output/20220117-132316_EMEA_PROD/credentials" }
|
||||
module "dynatrace_custom_service" { source = "./output/20220117-132316_EMEA_PROD/custom_services" }
|
||||
module "dynatrace_service_naming" { source = "./output/20220117-132316_EMEA_PROD/naming/services" }
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
if(len(sys.argv) == 1):
|
||||
try:
|
||||
process = subprocess.Popen(["terraform", "init"])
|
||||
outs = process.wait(timeout=10*60)
|
||||
print("[DEBUG]", "Process return code:", outs)
|
||||
except subprocess.TimeoutExpired:
|
||||
print("[DEBUG]", "Exception occured:", subprocess.TimeoutExpired)
|
||||
print("[DEBUG]", "Killing process.")
|
||||
process.kill()
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
dynatrace = {
|
||||
version = "1.9.1"
|
||||
source = "dynatrace-oss/dynatrace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
san.py
3
san.py
|
|
@ -1,3 +0,0 @@
|
|||
import subprocess
|
||||
process = subprocess.Popen([".\\bin\\terraform-provider-dynatrace_v1.9.1.exe", "export", "dynatrace_alerting_profile"])
|
||||
print(process.returncode)
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
dynatrace = {
|
||||
version = "1.9.1"
|
||||
source = "dynatrace-oss/dynatrace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# module "configDir" {
|
||||
# source = "git::https://github.com/arnauagithub/DynatraceTerraformConfiguration.git?ref=20211130-151123"
|
||||
# }
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
dynatrace = {
|
||||
version = "1.9.1"
|
||||
source = "dynatrace-oss/dynatrace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue