diff --git a/examples/automation_accounts.tfvars b/examples/automation_accounts.tfvars index d7bdcd3b..8e2ec1a9 100644 --- a/examples/automation_accounts.tfvars +++ b/examples/automation_accounts.tfvars @@ -1,17 +1,24 @@ automation_accounts = { test_auto_acc = { - name = "automatio-account-test" + name = "automation-account-test" resource_group_ref = "rg_test" + sku_name = "Basic" local_authentication_enabled = true public_network_access_enabled = true - tags = { - Env = "Test" + identity = { + type = "SystemAssigned" } - encryption = { - key_ref = "kvkey_test1" - mi_ref = "id_test" + python_packages = { + requests = { + version = "2.32.3" + content_uri = "https://files.pythonhosted.org/packages/source/r/requests/requests-2.32.3.tar.gz" + } + } + + tags = { + Env = "Test" } } } @@ -29,72 +36,3 @@ resource_groups = { } } } - -virtual_networks = { - vnet_test = { - name = "vnet-test-dv-ne-01" - resource_group_ref = "rg_test" - cidr = ["10.10.10.0/24"] - subnets = { - snet_sqlmi = { - name = "snet-sql-managed-instance" - cidr = ["10.10.10.0/25"] - delegation = "sql_managed_instance" - } - snet_private_endpoints = { - name = "snet-private-endpoints" - cidr = ["10.10.10.128/25"] - service_endpoints = ["Microsoft.Storage", "Microsoft.KeyVault"] - } - } - } -} - -managed_identities = { - id_test = { - name = "id-test-dv-ne-01" - resource_group_ref = "rg_test" - } -} - -keyvaults = { - kv_test = { - name = "kv-test-dv-ne-01" - resource_group_ref = "rg_test" - network_rules = { - default_action = "Deny" - allowed_ips = ["10.10.10.10", "20.20.20.20"] - subnets = { - allow_app1 = { - subnet_ref = "vnet_test/snet_private_endpoints" - } - } - } - } -} - -key_vault_keys = { - kvkey_test1 = { - name = "generated-certificate" - key_vault_ref = "kv_test" - key_type = "RSA" - key_size = "2048" - - key_opts = [ - "decrypt", - "encrypt", - "sign", - "unwrapKey", - "verify", - "wrapKey", - ] - - rotation_policy = { - expire_after = "P90D" - notify_before_expiry = "P29D" - automatic = { - time_before_expiry = "P30D" - } - } - } -} diff --git a/examples/automation_runbooks.tfvars b/examples/automation_runbooks.tfvars index dab7b25b..57cf26b0 100644 --- a/examples/automation_runbooks.tfvars +++ b/examples/automation_runbooks.tfvars @@ -12,59 +12,18 @@ automation_runbooks = { Env = "Test" } - draft = { - edit_mode_enabled = true - output_types = ["string"] - - content_link = { - uri = "https://raw.githubusercontent.com/org/repo/dev/runbooks/cleanup.ps1" - version = "0.9.0" - - hash = { - algorithm = "SHA256" - value = "B32E61E3D26D9C94D2AAFF5735C542A829E94C6C7BBCE83B7298C11B9F678ABC" - } - } - - parameters = { - param_01 = { - key = "RetentionDays" - type = "Int" - mandatory = true - position = 1 - default_value = "30" - } - param_02 = { - key = "storageaccount" - type = "String" - mandatory = false - position = 2 - default_value = "mystorageacct" - } - } - } - publish_content_link = { - uri = "https://raw.githubusercontent.com/org/repo/main/runbooks/cleanup.ps1" - version = "1.0.0" - - hash = { - algorithm = "SHA256" - value = "C67F36DDA2AC0AAE7B44B69B7AA7BB22113E6543E0AD91A9A6DA27676B8D5A62" - } - } job_schedules = { daily = { - schedule_name = "Dailymidnight" + schedule_ref = "daily_schedule" parameters = { RetentionDays = "30" } } weekly = { - schedule_name = "weeklyreport" + schedule_ref = "weekly_schedule" parameters = { - RetentionDays = "90" - StorageAccount = "archivestorageacct" + RetentionDays = "90" } } } @@ -81,79 +40,31 @@ automation_accounts = { tags = { Env = "Test" } - encryption = { - key_ref = "kvkey_test1" - mi_ref = "id_test" - } } } -key_vault_keys = { - kvkey_test1 = { - name = "generated-certificate" - key_vault_ref = "kv_test" - key_type = "RSA" - key_size = "2048" - - key_opts = [ - "decrypt", - "encrypt", - "sign", - "unwrapKey", - "verify", - "wrapKey", - ] - - rotation_policy = { - expire_after = "P90D" - notify_before_expiry = "P29D" - automatic = { - time_before_expiry = "P30D" - } - } - } -} - -keyvaults = { - kv_test = { - name = "kv-test-dv-ne-01" +automation_schedules = { + daily_schedule = { resource_group_ref = "rg_test" - network_rules = { - default_action = "Deny" - allowed_ips = ["10.10.10.10", "20.20.20.20"] - subnets = { - allow_app1 = { - subnet_ref = "vnet_test/snet_private_endpoints" - } - } - } + acc_ref = "test_auto_acc" + name = "daily-midnight" + frequency = "Day" + interval = 1 + start_time = "2025-11-14T00:00:00Z" + expiry_time = "2026-01-01T00:00:00Z" + timezone = "UTC" + description = "Daily schedule at midnight" } -} -managed_identities = { - id_test = { - name = "id-test-dv-ne-01" + weekly_schedule = { resource_group_ref = "rg_test" - } -} - -virtual_networks = { - vnet_test = { - name = "vnet-test-dv-ne-01" - resource_group_ref = "rg_test" - cidr = ["10.10.10.0/24"] - subnets = { - snet_sqlmi = { - name = "snet-sql-managed-instance" - cidr = ["10.10.10.0/25"] - delegation = "sql_managed_instance" - } - snet_private_endpoints = { - name = "snet-private-endpoints" - cidr = ["10.10.10.128/25"] - service_endpoints = ["Microsoft.Storage", "Microsoft.KeyVault"] - } - } + acc_ref = "test_auto_acc" + name = "weekly-monday" + frequency = "Week" + interval = 1 + week_days = ["Monday"] + start_time = "2025-11-14T09:00:00Z" + description = "Runs every Monday at 9 AM UTC" } } @@ -162,10 +73,6 @@ resource_groups = { name = "rg-test-01" location = "northeurope" tags = { - DeployDate = "11/07/2025", - DeadLine = "11/07/2026", - Owner = "Test Test", - Project = "Test", } } } diff --git a/examples/keyvaults.tfvars b/examples/keyvaults.tfvars index 2b1f8d18..9c8832e4 100644 --- a/examples/keyvaults.tfvars +++ b/examples/keyvaults.tfvars @@ -47,16 +47,6 @@ virtual_networks = { } } - -log_analytics_workspaces = { - testw1 = { - name = "testw1-tc66" - resource_group_ref = "rg_test" - retention_in_days = 30 - } -} - - resource_groups = { rg_test = { name = "rg-test-dv-ne-01" diff --git a/src/automation_runbooks.tf b/src/automation_runbooks.tf index 5b94d1c8..973554ac 100644 --- a/src/automation_runbooks.tf +++ b/src/automation_runbooks.tf @@ -11,8 +11,20 @@ module "automation_runbooks" { resources = merge( { (var.landingzone.key) = { - automation_accounts = module.automation_accounts - resource_groups = module.resource_groups + automation_accounts = module.automation_accounts + resource_groups = module.resource_groups + managed_identities = module.managed_identities + automation_schedules = module.automation_schedules + linux_virtual_machines = { + for key, vm in module.virtual_machines : + key => vm.linux_virtual_machines[0] + if length(vm.linux_virtual_machines) > 0 + } + windows_virtual_machines = { + for key, vm in module.virtual_machines : + key => vm.windows_virtual_machines[0] + if length(vm.windows_virtual_machines) > 0 + } } }, { diff --git a/src/modules/automation_account/python_packages.tf b/src/modules/automation_account/python_packages.tf new file mode 100644 index 00000000..8e9efc9c --- /dev/null +++ b/src/modules/automation_account/python_packages.tf @@ -0,0 +1,12 @@ +resource "azurerm_automation_python3_package" "main" { + for_each = try(var.settings.python_packages, {}) + + name = try(each.value.name, each.key) + resource_group_name = try(local.resource_group_name, var.settings.resource_group_name) + automation_account_name = azurerm_automation_account.main.name + content_uri = each.value.content_uri + content_version = try(each.value.content_version, null) + hash_algorithm = try(each.value.hash_algorithm, null) + hash_value = try(each.value.hash_value, null) + tags = try(each.value.tags, local.tags) +} diff --git a/src/modules/automation_runbook/_locals.tf b/src/modules/automation_runbook/_locals.tf index 68d4cfe2..f725ec34 100644 --- a/src/modules/automation_runbook/_locals.tf +++ b/src/modules/automation_runbook/_locals.tf @@ -15,4 +15,45 @@ locals { var.global_settings.inherit_resource_group_tags ? local.resource_group.tags : {}, try(var.settings.tags, {}) ) + + # Resolve landing zone per job schedule + job_lzkeys = { + for js_key, js in try(var.settings.job_schedules, {}) : + js_key => try(js.parameters.lzkey, var.client_config.landingzone_key) + } + + # Resolve parameters + job_schedule_parameters = { + for js_key, js in try(var.settings.job_schedules, {}) : + + js_key => merge( + # 1. Resolve all parameters (keep original keys) + { + for p_key, p_val in try(js.parameters, {}) : + p_key => ( + # CASE 1: resolve reference if ends with _ref + endswith(p_key, "_ref") && length(trimspace(p_val)) > 0 ? + try( + lookup( + lookup( + var.resources[local.job_lzkeys[js_key]], + split("/", p_val)[0], + {} + ), + split("/", p_val)[1], + {} + )[split("/", p_val)[2]], + null + ) + # CASE 2: direct value + : p_val + ) + }, + + # 2. Always set subscription_id + { + subscription_id = try(js.parameters.subscription_id, var.global_settings.subscription_id) + } + ) + } } diff --git a/src/modules/automation_runbook/main.tf b/src/modules/automation_runbook/main.tf index 3e631503..cecf2304 100644 --- a/src/modules/automation_runbook/main.tf +++ b/src/modules/automation_runbook/main.tf @@ -65,11 +65,12 @@ resource "azurerm_automation_runbook" "main" { dynamic "job_schedule" { for_each = try(var.settings.job_schedules, {}) content { - schedule_name = job_schedule.value.schedule_name - parameters = tomap({ - for k, v in try(job_schedule.value.parameters, {}) : - lower(k) => v - }) + schedule_name = try( + var.resources[try(job_schedule.value.job_lz_key, var.client_config.landingzone_key)] + .automation_schedules[job_schedule.value.schedule_ref].name, + job_schedule.value.schedule_name + ) + parameters = local.job_schedule_parameters[job_schedule.key] } } } diff --git a/src/modules/virtual_machines/linux_virtual_machine/_outputs.tf b/src/modules/virtual_machines/linux_virtual_machine/_outputs.tf index 13ab3947..04a9e8c7 100644 --- a/src/modules/virtual_machines/linux_virtual_machine/_outputs.tf +++ b/src/modules/virtual_machines/linux_virtual_machine/_outputs.tf @@ -2,6 +2,10 @@ output "id" { value = azurerm_linux_virtual_machine.main.id } +output "name" { + value = azurerm_linux_virtual_machine.main.name +} + output "private_ip_addresses" { value = azurerm_linux_virtual_machine.main.private_ip_addresses } diff --git a/src/modules/virtual_machines/virtual_machine_default/_ouputs.tf b/src/modules/virtual_machines/virtual_machine_default/_ouputs.tf index 521eb59a..b677b60a 100644 --- a/src/modules/virtual_machines/virtual_machine_default/_ouputs.tf +++ b/src/modules/virtual_machines/virtual_machine_default/_ouputs.tf @@ -1,3 +1,7 @@ output "id" { value = azurerm_virtual_machine.main.id } + +output "name" { + value = azurerm_virtual_machine.main.name +} diff --git a/src/modules/virtual_machines/windows_virtual_machine/_ouputs.tf b/src/modules/virtual_machines/windows_virtual_machine/_ouputs.tf index 4c5a9cb4..27d11f44 100644 --- a/src/modules/virtual_machines/windows_virtual_machine/_ouputs.tf +++ b/src/modules/virtual_machines/windows_virtual_machine/_ouputs.tf @@ -1,3 +1,7 @@ output "id" { value = azurerm_windows_virtual_machine.main.id } + +output "name" { + value = azurerm_windows_virtual_machine.main.name +} diff --git a/src/mssql_servers.tf b/src/mssql_servers.tf index e8dd0073..7c745ae5 100644 --- a/src/mssql_servers.tf +++ b/src/mssql_servers.tf @@ -39,7 +39,7 @@ module "mssql_failover_group" { resources = merge( { (var.landingzone.key) = { - mssql_servers = module.mssql_servers + mssql_servers = module.mssql_servers } }, { @@ -47,5 +47,3 @@ module "mssql_failover_group" { } ) } - -