Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex Environmental Name Replacements #178

Merged
merged 8 commits into from
Apr 26, 2021
10 changes: 5 additions & 5 deletions src/core/globals.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@
{
"varname": "tf_environment",
"type": "text",
"default_val": "env:TF_ENV",
"default_val": "${env:TF_ENV}",
"description": "Terraform azurerm environment (e.g. 'public') see: https://www.terraform.io/docs/language/settings/backends/azurerm.html#environment",
"options": []
},
{
"varname": "mlz_cloud",
"type": "text",
"default_val": "env:MLZ_CLOUDNAME",
"default_val": "${env:MLZ_CLOUDNAME}",
"description": "Azure cloud being deployed to, # e.g. 'AzureCloud' or 'AzureUSGovernment', etc",
"options": []
},
{
"varname": "mlz_tenantid",
"type": "text",
"default_val": "env:TENANT_ID",
"default_val": "${env:TENANT_ID}",
"description": "Tenant ID where your subscriptions live",
"options": []
},
{
"varname": "mlz_metadatahost",
"type": "text",
"default_val": "env:MLZ_METADATAHOST",
"default_val": "${env:MLZ_METADATAHOST}",
"description": "Azure Metadata Service endpoint. (e.g 'management.azure.com' or 'management.usgovcloudapi.net')",
"options": []
},
{
"varname": "mlz_location",
"type": "text",
"default_val": "env:MLZ_LOCATION",
"default_val": "${env:MLZ_LOCATION}",
"description": "The location that you're deploying to (e.g. 'eastus')",
"options": []
}
Expand Down
20 changes: 10 additions & 10 deletions src/core/saca-hub/saca-hub.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@
{
"varname": "saca_subid",
"type": "text",
"default_val": "env:HUB_SUBSCRIPTION_ID",
"default_val": "${env:HUB_SUBSCRIPTION_ID}",
"description": "The subscription id where the SACA hub lives",
"options": []
},
{
"varname": "saca_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-saca",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-saca",
"description": "Resource group name",
"options": []
},
{
"varname": "saca_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-saca",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-saca",
"description": "Virtual Network Name",
"options": []
},
{
"varname": "saca_lawsname",
"type": "text",
"default_val": "laws-eastus-mlz-saca",
"default_val": "laws-${env:MLZ_LOCATION}-mlz-saca",
"description": "Name for log analytic workspace",
"options": []
},
Expand All @@ -48,42 +48,42 @@
{
"varname": "tier0_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-t0",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-t0",
"description": "Tier 0 resource group name",
"options": []
},
{
"varname": "tier0_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-t0",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-t0",
"description": "Tier 0 virtual network name",
"options": []
},
{
"varname": "tier1_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-t1",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-t1",
"description": "Tier 1 resource group name",
"options": []
},
{
"varname": "tier1_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-t1",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-t1",
"description": "Tier one virtual network name",
"options": []
},
{
"varname": "tier2_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-t2",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-t2",
"description": "Tier 2 resource group name",
"options": []
},
{
"varname": "tier2_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-t2",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-t2",
"description": "Tier 2 virtual network name",
"options": []
},
Expand Down
16 changes: 8 additions & 8 deletions src/core/tier-0/tier-0.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
{
"varname": "saca_subid",
"type": "text",
"default_val": "env:HUB_SUBSCRIPTION_ID",
"default_val": "${env:HUB_SUBSCRIPTION_ID}",
"description": "Saca Hub Subscription ID",
"options": []
},
{
"varname": "saca_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-saca",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Hub Resource Group Name",
"options": []
},
{
"varname": "saca_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-saca",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Virtual Network Name",
"options": []
},
Expand All @@ -35,28 +35,28 @@
{
"varname": "saca_lawsname",
"type": "text",
"default_val": "laws-eastus-mlz-saca",
"default_val": "laws-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Log Analytic Workspace Name",
"options": []
},
{
"varname": "tier0_subid",
"type": "text",
"default_val": "env:TIER0_SUBSCRIPTION_ID",
"default_val": "${env:TIER0_SUBSCRIPTION_ID}",
"description": "Tier0 Subscription Id",
"options": []
},
{
"varname": "tier0_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-t0",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-t0",
"description": "Tier0 Resource Group Name",
"options": []
},
{
"varname": "tier0_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-t0",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-t0",
"description": "Tier0 Virtual Network Name",
"options": []
},
Expand Down Expand Up @@ -131,4 +131,4 @@
}
]
}
}
}
16 changes: 8 additions & 8 deletions src/core/tier-1/tier-1.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
{
"varname": "saca_subid",
"type": "text",
"default_val": "env:HUB_SUBSCRIPTION_ID",
"default_val": "${env:HUB_SUBSCRIPTION_ID}",
"description": "Saca Hub Subscription ID",
"options": []
},
{
"varname": "saca_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-saca",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Hub Resource Group Name",
"options": []
},
{
"varname": "saca_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-saca",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Virtual Network Name",
"options": []
},
Expand All @@ -35,28 +35,28 @@
{
"varname": "saca_lawsname",
"type": "text",
"default_val": "laws-eastus-mlz-saca",
"default_val": "laws-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Log Analytic Workspace Name",
"options": []
},
{
"varname": "tier1_subid",
"type": "text",
"default_val": "env:TIER1_SUBSCRIPTION_ID",
"default_val": "${env:TIER1_SUBSCRIPTION_ID}",
"description": "Tier0 Subscription Id",
"options": []
},
{
"varname": "tier1_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-t1",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-t1",
"description": "Tier0 Resource Group Name",
"options": []
},
{
"varname": "tier1_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-t1",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-t1",
"description": "Tier0 Virtual Network Name",
"options": []
},
Expand Down Expand Up @@ -131,4 +131,4 @@
}
]
}
}
}
16 changes: 8 additions & 8 deletions src/core/tier-2/tier-2.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
{
"varname": "saca_subid",
"type": "text",
"default_val": "env:HUB_SUBSCRIPTION_ID",
"default_val": "${env:HUB_SUBSCRIPTION_ID}",
"description": "Saca Hub Subscription ID",
"options": []
},
{
"varname": "saca_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-saca",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Hub Resource Group Name",
"options": []
},
{
"varname": "saca_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-saca",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Virtual Network Name",
"options": []
},
Expand All @@ -35,28 +35,28 @@
{
"varname": "saca_lawsname",
"type": "text",
"default_val": "laws-eastus-mlz-saca",
"default_val": "laws-${env:MLZ_LOCATION}-mlz-saca",
"description": "Saca Log Analytic Workspace Name",
"options": []
},
{
"varname": "tier2_subid",
"type": "text",
"default_val": "env:TIER2_SUBSCRIPTION_ID",
"default_val": "${env:TIER2_SUBSCRIPTION_ID}",
"description": "Tier0 Subscription Id",
"options": []
},
{
"varname": "tier2_rgname",
"type": "text",
"default_val": "rg-eastus-mlz-t2",
"default_val": "rg-${env:MLZ_LOCATION}-mlz-t2",
"description": "Tier2 Resource Group Name",
"options": []
},
{
"varname": "tier2_vnetname",
"type": "text",
"default_val": "vn-eastus-mlz-t2",
"default_val": "vn-${env:MLZ_LOCATION}-mlz-t2",
"description": "Tier2 Virtual Network Name",
"options": []
},
Expand Down Expand Up @@ -131,4 +131,4 @@
}
]
}
}
}
19 changes: 17 additions & 2 deletions src/front/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Provides a set of utility functions to be called from the primary API
import os
import json
import re
from dominate.tags import *
from typing import Union

# Re-usable variable sets
env_match = re.compile("\${env:([0-9a-zA-Z_]+)}")

def dotted_write(prop_name: str, val: Union[int, str], target_dict: dict):
"""
Purpose: Function takes in a property value to be mapped that contains .'s in a string.
Expand Down Expand Up @@ -84,7 +88,7 @@ def build_form(form_doc: dict):
# Process environment options
if type(el_item["default_val"]) != bool:
if "env:" in el_item["default_val"]:
el_item["default_val"] = os.getenv(el_item["default_val"].replace("env:", ""), "")
el_item["default_val"] = env_match.sub(environ_replace, el_item["default_val"])
span(el_item["varname"], cls="input-group-text")
if el_item["type"] == "text":
input_(id=el_item["varname"], cls="form-control", value=el_item["default_val"], name=el_item["varname"])
Expand All @@ -105,4 +109,15 @@ def build_form(form_doc: dict):
with doc_form:
input_(value="Execute Terraform", type="submit")

return doc_form
return doc_form


def environ_replace(match_obj):
"""
Purpose: Iterate over the resulting match groups from a regex and return the matching environment variable
form to be appended to the front end UI

:form_doc: a dictionary derived from a loaded json
"""
for x in match_obj.groups():
return os.getenv(x)