Skip to content

Commit 9f474a6

Browse files
committed
Move exists = true method
1 parent 358a884 commit 9f474a6

3 files changed

Lines changed: 30 additions & 17 deletions

File tree

.github/workflows/end-to-end-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,11 @@ jobs:
302302
$Inputs["resource_name_suffix"] = $uniqueId
303303
$architectureFilePath = "${{ env.STARTER_MODULE_FOLDER }}/templates/$starterModule/lib/architecture_definitions/alz_custom.alz_architecture_definition.yaml"
304304
$architectureFile = Get-Content -Path $architectureFilePath -Raw
305-
$architectureFile = $architectureFile.Replace("id: test", "id: test-$uniqueId")
305+
$architectureFile = $architectureFile.Replace("- id: child-test", "- id: child-test-$uniqueId")
306+
$architectureFile = $architectureFile.Replace("display_name: Child Test", "display_name: Child Test $uniqueId")
307+
$architectureFile = $architectureFile.Replace("- id: test", "- id: test-$uniqueId")
306308
$architectureFile = $architectureFile.Replace("display_name: Test", "display_name: Test $uniqueId")
309+
$architectureFile = $architectureFile.Replace("parent_id: test", "prefix: $uniqueId")
307310
$architectureFile | Out-File -FilePath $architectureFilePath -Encoding utf8 -Force
308311
}
309312
Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# Get the intermediate root management group from the terraform architecture file or bicep parameters
12
locals {
23
is_terraform_iac_type = var.iac_type == "terraform"
3-
terraform_architecture = local.is_terraform_iac_type ? endswith(var.terraform_architecture_file_path, ".yaml") || endswith(var.terraform_architecture_file_path, ".json") ? yamldecode(file("${var.module_folder_path}/${var.terraform_architecture_file_path}")) : jsondecode(file("${var.module_folder_path}/${var.terraform_architecture_file_path}")) : null
4+
terraform_architecture_file_path = "${var.module_folder_path}/${var.terraform_architecture_file_path}"
5+
terraform_architecture_file_extension = split(".", var.terraform_architecture_file_path)[length(split(".", var.terraform_architecture_file_path)) - 1]
6+
terraform_architecture_file_is_yaml = local.terraform_architecture_file_extension == "yaml" || local.terraform_architecture_file_extension == "yml"
7+
terraform_architecture = local.is_terraform_iac_type ? (local.terraform_architecture_file_is_yaml ? yamldecode(file(local.terraform_architecture_file_path)) : jsondecode(file(local.terraform_architecture_file_path))) : null
48
terraform_intermediate_root_management_group = local.is_terraform_iac_type ? ([for management_group in local.terraform_architecture.management_groups : management_group if management_group.parent_id == null])[0] : null
59
intermediate_root_management_group = local.is_terraform_iac_type ? {
610
id = local.terraform_intermediate_root_management_group.id
@@ -11,17 +15,28 @@ locals {
1115
}
1216
}
1317

18+
# Transform the intermediate root management group in the terraform architecture file to ensure it is marked as existing
1419
locals {
15-
import_block = <<EOT
16-
import {
17-
to = ${var.terraform_intermediate_root_management_group_state_resource_path_for_import}["${local.intermediate_root_management_group.id}"]
18-
id = "/providers/Microsoft.Management/managementGroups/${local.intermediate_root_management_group.id}"
19-
}
20-
EOT
20+
terraform_management_groups_non_root = local.is_terraform_iac_type ? [ for management_group in local.terraform_architecture.management_groups : management_group if management_group.parent_id != null ] : null
21+
terraform_intermediate_root_management_group_updated = local.is_terraform_iac_type ? merge(
22+
local.terraform_intermediate_root_management_group,
23+
{
24+
exists = true
25+
}
26+
) : null
27+
terraform_architecture_file_content_final = local.is_terraform_iac_type ? merge(
28+
local.terraform_architecture,
29+
{
30+
management_groups = concat(
31+
[local.terraform_intermediate_root_management_group_updated],
32+
local.terraform_management_groups_non_root
33+
)
34+
}
35+
) : null
2136

22-
import_block_files = local.is_terraform_iac_type ? {
23-
"imports.management_groups.tf" = {
24-
content = local.import_block
37+
terraform_architecture_files = local.is_terraform_iac_type ? {
38+
(var.terraform_architecture_file_path) = {
39+
content = local.terraform_architecture_file_is_yaml ? yamlencode(local.terraform_architecture_file_content_final) : jsonencode(local.terraform_architecture_file_content_final)
2540
}
2641
} : {}
2742
}

modules/file_manipulation/outputs.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
output "repository_files" {
22
description = "Map of repository files with their content"
3-
value = merge(local.repository_files, local.import_block_files)
3+
value = merge(local.repository_files, local.terraform_architecture_files)
44
}
55

66
output "template_repository_files" {
@@ -17,8 +17,3 @@ output "intermediate_root_management_group_display_name" {
1717
description = "The display name of the intermediate root management group from the Terraform architecture"
1818
value = local.intermediate_root_management_group.display_name
1919
}
20-
21-
output "import_block" {
22-
description = "The import block for the intermediate root management group"
23-
value = local.import_block
24-
}

0 commit comments

Comments
 (0)