Skip to content
Merged
88 changes: 13 additions & 75 deletions examples/automation_accounts.tfvars
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Expand All @@ -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"
}
}
}
}
135 changes: 21 additions & 114 deletions examples/automation_runbooks.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand All @@ -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"
}
}

Expand All @@ -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",
}
}
}
10 changes: 0 additions & 10 deletions examples/keyvaults.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 14 additions & 2 deletions src/automation_runbooks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
},
{
Expand Down
12 changes: 12 additions & 0 deletions src/modules/automation_account/python_packages.tf
Original file line number Diff line number Diff line change
@@ -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)
}
41 changes: 41 additions & 0 deletions src/modules/automation_runbook/_locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
}
}
11 changes: 6 additions & 5 deletions src/modules/automation_runbook/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
}
Loading
Loading