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

feat: Fix malformed json from arch def template #57

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions modules/template_architecture_definition/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ locals {
# Customer has provided a custom architecture definition
has_architecture_definition_override = local.architecture_definition_override_path != ""

slz_architecture_definition_name = "slz"
fsi_architecture_definition_name = "fsi"

# SLZ archetypes
slz_global = ["\"global\""]

# FSI archetypes
fsi_root = ["\"fsi_root\""]

# SLZ/FSI confidential archetypes
confidential = ["\"confidential\""]

# ALZ archetypes
alz_root = ["\"root\""]
alz_platform = ["\"platform\""]
Expand All @@ -36,9 +24,7 @@ locals {
alz_identity = ["\"identity\""]

# management group layered archetypes
root = (local.enable_alz ?
(var.architecture_definition_name == local.slz_architecture_definition_name ? concat(local.slz_global, local.alz_root) : concat(local.fsi_root, local.alz_root))
: (var.architecture_definition_name == local.fsi_architecture_definition_name ? local.fsi_root : local.slz_global))
root = local.enable_alz ? local.alz_root : []
platform = local.enable_alz ? local.alz_platform : []
landing_zone = local.enable_alz ? local.alz_landing_zone : []
decommissioned = local.enable_alz ? local.alz_decommissioned : []
Expand All @@ -48,8 +34,8 @@ locals {
management = local.enable_alz ? local.alz_management : []
connectivity = local.enable_alz ? local.alz_connectivity : []
identity = local.enable_alz ? local.alz_identity : []
confidential_corp = local.enable_alz ? concat(local.confidential, local.alz_corp) : local.confidential
confidential_online = local.enable_alz ? concat(local.confidential, local.alz_online) : local.confidential
confidential_corp = local.enable_alz ? local.alz_corp : []
confidential_online = local.enable_alz ? local.alz_online : []

template_vars = {
architecture_definition_name = var.architecture_definition_name
Expand Down Expand Up @@ -80,5 +66,10 @@ locals {
confidential_online_archetypes = join(", ", local.confidential_online)
}

template_file = templatefile(local.template_file_path, local.template_vars)
unclean_templated_file_content = templatefile(local.template_file_path, local.template_vars)

# Templated file contents could have malformed json due hard-coded archetypes in the template file.
# This fixes commas in the json at beginning and end of arrays, and two consecutive commas in the arrays.
# Occurs when there are no archetypes in the array that is being used to replace the template variable.
template_file = replace(replace(replace(local.unclean_templated_file_content, "/\\[\\s*,\\s*/", "["), "/,\\s*\\]/", "]"), "/\\,\\s*,/", ",")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "${architecture_definition_name}",
"management_groups": [
{
"archetypes": [${root_archetypes}],
"archetypes": [${root_archetypes}, "global"],
"display_name": "Sovereign Landing Zone",
"exists": false,
"id": "${root_management_group_id}",
Expand Down Expand Up @@ -51,7 +51,7 @@
"parent_id": "${landing_zone_management_group_id}"
},
{
"archetypes": [${confidential_corp_archetypes}],
"archetypes": [${confidential_corp_archetypes}, "confidential"],
"display_name": "Confidential Corp",
"exists": false,
"id": "${confidential_corp_management_group_id}",
Expand All @@ -65,7 +65,7 @@
"parent_id": "${landing_zone_management_group_id}"
},
{
"archetypes": [${confidential_online_archetypes}],
"archetypes": [${confidential_online_archetypes}, "confidential"],
"display_name": "Confidential Online",
"exists": false,
"id": "${confidential_online_management_group_id}",
Expand Down
Loading