management_zones is used to create folders and also to compare.
parent
77112199be
commit
df57f7bd6d
59
README.md
59
README.md
|
|
@ -1,59 +0,0 @@
|
||||||
# TerraformOnboarding
|
|
||||||
The purpose of the exportConfig.py script is to export dynatrace specific services as terraform files. The importConfig.py script is used to additionally also export the states for each exported terraform file, since terraform does not do that by default.
|
|
||||||
|
|
||||||
|
|
||||||
# Setup
|
|
||||||
Run the following command to install all necessary dependencies:
|
|
||||||
|
|
||||||
```python
|
|
||||||
pip install -r requirements.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
In order to ensure full functionality a `.env` file is necessary with the following format:
|
|
||||||
|
|
||||||
```yml
|
|
||||||
# Environment URLs
|
|
||||||
CN_PREPROD_ENV_URL="https://dynatracemgd-cn.bmwgroup.net/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35"
|
|
||||||
CN_PROD_ENV_URL="https://dynatracemgd-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
|
||||||
EMEA_PREPROD_ENV_URL="https://qqk70169.live.dynatrace.com"
|
|
||||||
EMEA_PROD_ENV_URL="https://xxu26128.live.dynatrace.com"
|
|
||||||
NA_PREPROD_ENV_URL="https://onb44935.live.dynatrace.com"
|
|
||||||
NA_PROD_ENV_URL="https://wgv50241.live.dynatrace.com"
|
|
||||||
|
|
||||||
# Environment Tokens
|
|
||||||
CN_PREPROD_API_TOKEN="<your-token>"
|
|
||||||
CN_PROD_API_TOKEN="<your-token>"
|
|
||||||
EMEA_PREPROD_API_TOKEN="<your-token>"
|
|
||||||
EMEA_PROD_API_TOKEN="<your-token>"
|
|
||||||
NA_PREPROD_API_TOKEN="<your-token>"
|
|
||||||
NA_PROD_API_TOKEN="<your-token>"
|
|
||||||
```
|
|
||||||
Place the `.env` file within the root directory of the project folder:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
TerraformDynatrace Porter # Project Folder
|
|
||||||
├─── res
|
|
||||||
├─── templates
|
|
||||||
├─── .env # Add the environment file
|
|
||||||
├─── .gitignore
|
|
||||||
├─── README.md
|
|
||||||
├─── exportConfig.py
|
|
||||||
├─── imortConfig.py
|
|
||||||
├─── main.tf
|
|
||||||
└─── requirements.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
# Run
|
|
||||||
You can simply run the script by executing the following example command within the projects root directory:
|
|
||||||
|
|
||||||
```python
|
|
||||||
python exportConfig.py
|
|
||||||
python importConfig.py
|
|
||||||
```
|
|
||||||
**Note:** First run the exportConfig.py script and once that is done run the importConfig.py script.
|
|
||||||
|
|
||||||
|
|
||||||
# Version
|
|
||||||
```python
|
|
||||||
Python 3.9.9
|
|
||||||
```
|
|
||||||
12
adapter.py
12
adapter.py
|
|
@ -44,10 +44,11 @@ def createFolderStructure():
|
||||||
|
|
||||||
# [AA 2022.01.20] Filter out module.tf and main.tf
|
# [AA 2022.01.20] Filter out module.tf and main.tf
|
||||||
if len(splittedFilename) == 5:
|
if len(splittedFilename) == 5:
|
||||||
resourceID = splittedFilename[1]
|
# resourceID = splittedFilename[1]
|
||||||
moduleName, resourceName = readFile(file)
|
# moduleName, resourceName = readFile(file)
|
||||||
|
|
||||||
# [AA 2022.01.20] Create direcotires and copy associated files
|
# [AA 2022.01.20] Create direcotires and copy associated files
|
||||||
|
resourceName = os.path.basename(file).split(".")[0].split(" ")[0]
|
||||||
resourcePath = os.path.join(outputFolder + environment + "/", resourceName)
|
resourcePath = os.path.join(outputFolder + environment + "/", resourceName)
|
||||||
# if not resourcePath in resourcePaths.keys():
|
# if not resourcePath in resourcePaths.keys():
|
||||||
# resourcePaths.setdefault("resourcePaths", [])
|
# resourcePaths.setdefault("resourcePaths", [])
|
||||||
|
|
@ -58,7 +59,6 @@ def createFolderStructure():
|
||||||
return management_zones
|
return management_zones
|
||||||
|
|
||||||
def filterCondition(filename):
|
def filterCondition(filename):
|
||||||
|
|
||||||
return '/dashboards/' in filename or '/alerting_profiles/' in filename;
|
return '/dashboards/' in filename or '/alerting_profiles/' in filename;
|
||||||
#'/dashboards/' in filename or
|
#'/dashboards/' in filename or
|
||||||
|
|
||||||
|
|
@ -69,10 +69,10 @@ def fillOtherResources(management_zones):
|
||||||
for management_zone in management_zones:
|
for management_zone in management_zones:
|
||||||
for element in otherResource_filterd:
|
for element in otherResource_filterd:
|
||||||
elementName = os.path.basename(element).split(".")[0].split(" ")[0]
|
elementName = os.path.basename(element).split(".")[0].split(" ")[0]
|
||||||
management_zone_name = os.path.basename(management_zone).split(".")[0].split(" ")[0]
|
management_zone_folder_name = os.path.basename(management_zone).split(".")[0].split(" ")[0]
|
||||||
folder = os.path.dirname(os.path.dirname(management_zone)).replace("export","")
|
folder = os.path.dirname(os.path.dirname(management_zone)).replace("export","")
|
||||||
if elementName == management_zone_name:
|
if elementName == management_zone_folder_name:
|
||||||
copyFile("./" + element, "./output" + folder + "/" + os.path.basename(element))
|
copyFile("./" + element, "./output" + folder + "/" + management_zone_folder_name + "/" + os.path.basename(element))
|
||||||
print("[DEBUG]", "File %s copied to %s." % (os.path.basename(element), "./output" + folder + "/" + os.path.basename(element)))
|
print("[DEBUG]", "File %s copied to %s." % (os.path.basename(element), "./output" + folder + "/" + os.path.basename(element)))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue