Skip to content

Commit b91dcab

Browse files
committed
Add logic for networktype and subscription id replacment
1 parent 8ec856b commit b91dcab

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

alz/local/locals.files.tf

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ locals {
3030
deploymentType = script_file.deploymentType
3131
firstRunWhatIf = local.is_classic_bicep ? format("%s%s", "$", script_file.firstRunWhatIf) : null
3232
group = script_file.group
33+
networkType = try(script_file.networkType, "")
3334
} if !local.is_classic_bicep || try(script_file.networkType, "") == "" || try(script_file.networkType, "") == local.networking_type } : {}
3435

3536
deploy_script_files_parsed = { for deploy_script_file in local.deploy_script_files : "${local.target_folder_name}/${deploy_script_file}" =>
@@ -63,8 +64,27 @@ locals {
6364
} if local.is_bicep_iac_type ? true : !endswith(key, ".ps1")
6465
}
6566

67+
# Replace subscription ID placeholders in .bicepparam files
68+
module_files_with_subscriptions = { for key, value in local.module_files : key =>
69+
{
70+
content = endswith(key, ".bicepparam") ? replace(
71+
replace(
72+
replace(
73+
value.content,
74+
"{{your-management-subscription-id}}",
75+
try(var.subscription_ids["management"], var.subscription_id_management, "")
76+
),
77+
"{{your-connectivity-subscription-id}}",
78+
try(var.subscription_ids["connectivity"], var.subscription_id_connectivity, "")
79+
),
80+
"{{your-identity-subscription-id}}",
81+
try(var.subscription_ids["identity"], var.subscription_id_identity, "")
82+
) : value.content
83+
}
84+
}
85+
6686
# Build a map of module files with types that are supported
67-
module_files_supported = { for key, value in local.module_files : key => value if value.content != "unsupported_file_type" && !endswith(key, "-cache.json") && !endswith(key, local.bicep_config_file_path) }
87+
module_files_supported = { for key, value in local.module_files_with_subscriptions : key => value if value.content != "unsupported_file_type" && !endswith(key, "-cache.json") && !endswith(key, local.bicep_config_file_path) }
6888

6989
# Build a list of files to exclude from the repository based on the on-demand folders (only for classic bicep)
7090
excluded_module_files = local.is_classic_bicep ? distinct(flatten([for exclusion in local.on_demand_folders :

alz/local/scripts-bicep-avm/deploy-local.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ if ($deployApproved -ne "yes") {
1818
}
1919

2020
%{ for script_file in script_files ~}
21+
%{ if try(script_file.networkType, "") != "" ~}
22+
# Running deployment stack for ${script_file.displayName} (Network Type: ${script_file.networkType})
23+
if ($env:NETWORK_TYPE -eq "${script_file.networkType}") {
24+
& (Join-Path $scriptRoot 'bicep-deploy.ps1') `
25+
-name "${script_file.name}" `
26+
-displayName "${script_file.displayName}" `
27+
-templateFilePath "${script_file.templateFilePath}" `
28+
-templateParametersFilePath "${script_file.templateParametersFilePath}" `
29+
-managementGroupId ${script_file.managementGroupIdVariable} `
30+
-subscriptionId ${script_file.subscriptionIdVariable} `
31+
-resourceGroupName ${script_file.resourceGroupNameVariable} `
32+
-location $env:LOCATION `
33+
-deploymentType "${script_file.deploymentType}"
34+
} else {
35+
Write-Host "Skipping ${script_file.displayName} - Network Type is $env:NETWORK_TYPE, requires ${script_file.networkType}" -ForegroundColor Yellow
36+
}
37+
%{ else ~}
2138
# Running deployment stack for ${script_file.displayName}
2239
& (Join-Path $scriptRoot 'bicep-deploy.ps1') `
2340
-name "${script_file.name}" `
@@ -29,5 +46,6 @@ if ($deployApproved -ne "yes") {
2946
-resourceGroupName ${script_file.resourceGroupNameVariable} `
3047
-location $env:LOCATION `
3148
-deploymentType "${script_file.deploymentType}"
49+
%{ endif ~}
3250

3351
%{ endfor ~}

0 commit comments

Comments
 (0)