-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate-variables
executable file
·43 lines (35 loc) · 1.14 KB
/
generate-variables
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
import os
import hcl2
import json
def generate_variables(working_dir='.'):
vars = {}
var_rows = ""
with open(f"{working_dir}/variables.tf", 'r') as file:
for var in hcl2.load(file)['variable']:
for var_name in var:
print(var_name)
data = var[var_name]
if data.get('sensitive', False):
continue
vars[var_name] = data
for var_name, var in vars.items():
# print(var_name)
# print(json.dumps(var))
updated_name = var_name.replace("-", "_")
var_rows += f" {updated_name} = \"${{jsonencode(var.{var_name})}}\"\n"
config_map = f"""resource "kubernetes_config_map" "terraform-variables" {{
# this file is generated via pre-commit, DO NOT EDIT !
depends_on = [null_resource.wait-for-tf-cod-chart-build]
metadata {{
name = "terraform-variables"
}}
data = {{
{var_rows}
}}
}}
"""
with open(f"{working_dir}/tf-smoketest-variables.tf", "w") as cm:
cm.write(config_map)
generate_variables('.')
generate_variables('./azure')