diff --git a/src/core/globals.front.json b/src/core/globals.front.json index fdcb56f3d..00e7ff79f 100644 --- a/src/core/globals.front.json +++ b/src/core/globals.front.json @@ -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": [] } diff --git a/src/core/saca-hub/saca-hub.front.json b/src/core/saca-hub/saca-hub.front.json index a7f1e4534..d9eb8a33b 100644 --- a/src/core/saca-hub/saca-hub.front.json +++ b/src/core/saca-hub/saca-hub.front.json @@ -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": [] }, @@ -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": [] }, diff --git a/src/core/tier-0/tier-0.front.json b/src/core/tier-0/tier-0.front.json index 24ed0b7af..a888d64f9 100644 --- a/src/core/tier-0/tier-0.front.json +++ b/src/core/tier-0/tier-0.front.json @@ -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": [] }, @@ -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": [] }, @@ -131,4 +131,4 @@ } ] } -} \ No newline at end of file +} diff --git a/src/core/tier-1/tier-1.front.json b/src/core/tier-1/tier-1.front.json index 61ef150db..1ff473e2a 100644 --- a/src/core/tier-1/tier-1.front.json +++ b/src/core/tier-1/tier-1.front.json @@ -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": [] }, @@ -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": [] }, @@ -131,4 +131,4 @@ } ] } -} \ No newline at end of file +} diff --git a/src/core/tier-2/tier-2.front.json b/src/core/tier-2/tier-2.front.json index be8fd4ed1..62cd0b0d4 100644 --- a/src/core/tier-2/tier-2.front.json +++ b/src/core/tier-2/tier-2.front.json @@ -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": [] }, @@ -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": [] }, @@ -131,4 +131,4 @@ } ] } -} \ No newline at end of file +} diff --git a/src/front/lib/utils.py b/src/front/lib/utils.py index e6e8fb3c3..6d4da12f5 100644 --- a/src/front/lib/utils.py +++ b/src/front/lib/utils.py @@ -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. @@ -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"]) @@ -105,4 +109,15 @@ def build_form(form_doc: dict): with doc_form: input_(value="Execute Terraform", type="submit") - return doc_form \ No newline at end of file + 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)