diff --git a/logic_app.tf b/logic_app.tf index 29f10ed982..a68ac22417 100644 --- a/logic_app.tf +++ b/logic_app.tf @@ -154,9 +154,13 @@ module "logic_app_standard" { private_dns = local.combined_objects_private_dns vnets = local.combined_objects_networking virtual_subnets = local.combined_objects_virtual_subnets - base_tags = try(local.global_settings.inherit_tags, false) + #base_tags = try(local.global_settings.inherit_tags, false) vnet_integration = try(each.value.vnet_integration, {}) combined_objects = local.dynamic_app_settings_combined_objects + base_tags = local.global_settings.inherit_tags + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group_key, each.value.resource_group.key)] + resource_group_name = can(each.value.resource_group.name) || can(each.value.resource_group_name) ? try(each.value.resource_group.name, each.value.resource_group_name) : null + location = try(local.global_settings.regions[each.value.region], null) } output "logic_app_standard" { diff --git a/modules/compute/virtual_machine_extensions/AADLogin.tf b/modules/compute/virtual_machine_extensions/AADLogin.tf index fbfa5084d3..e1c754e713 100644 --- a/modules/compute/virtual_machine_extensions/AADLogin.tf +++ b/modules/compute/virtual_machine_extensions/AADLogin.tf @@ -6,6 +6,7 @@ resource "azurerm_virtual_machine_extension" "AADLogin" { type = local.aadlogin_type type_handler_version = var.extension.type_handler_version auto_upgrade_minor_version = true + tags = merge(local.tags, try(each.value.tags, null)) } locals { diff --git a/modules/compute/virtual_machine_extensions/LinuxDiagnostic.tf b/modules/compute/virtual_machine_extensions/LinuxDiagnostic.tf index dbbc6a7570..99e6ce21f2 100644 --- a/modules/compute/virtual_machine_extensions/LinuxDiagnostic.tf +++ b/modules/compute/virtual_machine_extensions/LinuxDiagnostic.tf @@ -8,6 +8,7 @@ resource "azurerm_virtual_machine_extension" "linux_diagnostic" { type_handler_version = try(var.extension.type_handler_version, "4.0") automatic_upgrade_enabled = try(var.extension.auto_upgrade_minor_version, false) auto_upgrade_minor_version = try(var.extension.auto_upgrade_minor_version, true) + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode({ "ladCfg" = jsondecode(templatefile(local.linux_diagnostic.ladcfg, { virtual_machine_id = var.virtual_machine_id })) diff --git a/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf b/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf index 655734e5c2..56d74c563f 100644 --- a/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf +++ b/modules/compute/virtual_machine_extensions/Microsoft.EnterpriseCloud.Monitoring.tf @@ -8,6 +8,7 @@ resource "azurerm_virtual_machine_extension" "monitoring" { publisher = "Microsoft.EnterpriseCloud.Monitoring" type = "MicrosoftMonitoringAgent" type_handler_version = "1.0" + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode( { diff --git a/modules/compute/virtual_machine_extensions/custom_script.tf b/modules/compute/virtual_machine_extensions/custom_script.tf index 2e87187464..ebe81011f0 100644 --- a/modules/compute/virtual_machine_extensions/custom_script.tf +++ b/modules/compute/virtual_machine_extensions/custom_script.tf @@ -6,6 +6,7 @@ resource "azurerm_virtual_machine_extension" "custom_script" { type = local.type type_handler_version = local.type_handler_version auto_upgrade_minor_version = true + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode( { diff --git a/modules/compute/virtual_machine_extensions/devops_selfhosted_agent.tf b/modules/compute/virtual_machine_extensions/devops_selfhosted_agent.tf index dede53f75f..ee1c88a944 100644 --- a/modules/compute/virtual_machine_extensions/devops_selfhosted_agent.tf +++ b/modules/compute/virtual_machine_extensions/devops_selfhosted_agent.tf @@ -20,6 +20,7 @@ resource "azurerm_virtual_machine_extension" "devops_selfhosted_agent" { publisher = "Microsoft.Azure.Extensions" type = "CustomScript" type_handler_version = "2.1" + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode(local.devops_selfhosted_agent_settings) protected_settings = jsonencode(local.devops_selfhosted_agent_protected_settings) diff --git a/modules/compute/virtual_machine_extensions/domain_join.tf b/modules/compute/virtual_machine_extensions/domain_join.tf index 52638ef462..852841e385 100644 --- a/modules/compute/virtual_machine_extensions/domain_join.tf +++ b/modules/compute/virtual_machine_extensions/domain_join.tf @@ -6,6 +6,7 @@ resource "azurerm_virtual_machine_extension" "domainjoin" { type = "JsonADDomainExtension" type_handler_version = try(var.extension.type_handler_version, "1.3") auto_upgrade_minor_version = try(var.extension.auto_upgrade_minor_version, true) + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode( { diff --git a/modules/compute/virtual_machine_extensions/generic_extensions.tf b/modules/compute/virtual_machine_extensions/generic_extensions.tf index d2665659f4..6ea62822eb 100644 --- a/modules/compute/virtual_machine_extensions/generic_extensions.tf +++ b/modules/compute/virtual_machine_extensions/generic_extensions.tf @@ -12,6 +12,7 @@ resource "azurerm_virtual_machine_extension" "genext" { auto_upgrade_minor_version = try(each.value.auto_upgrade_minor_version, null) automatic_upgrade_enabled = try(each.value.automatic_upgrade_enabled, null) failure_suppression_enabled = try(each.value.failure_suppression_enabled, null) + tags = merge(local.tags, try(each.value.tags, null)) settings = try(each.value.settings, null) protected_settings = try(each.value.protected_settings, null) diff --git a/modules/compute/virtual_machine_extensions/keyvaultforwindows.tf b/modules/compute/virtual_machine_extensions/keyvaultforwindows.tf index a35f8ef272..419eea5134 100644 --- a/modules/compute/virtual_machine_extensions/keyvaultforwindows.tf +++ b/modules/compute/virtual_machine_extensions/keyvaultforwindows.tf @@ -7,6 +7,7 @@ resource "azurerm_virtual_machine_extension" "keyvault_for_windows" { type = "KeyVaultForWindows" type_handler_version = try(var.extension.type_handler_version, "1.0") auto_upgrade_minor_version = try(var.extension.auto_upgrade_minor_version, true) + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode( { diff --git a/modules/compute/virtual_machine_extensions/main.tf b/modules/compute/virtual_machine_extensions/main.tf index 978aeb9631..182eae4385 100644 --- a/modules/compute/virtual_machine_extensions/main.tf +++ b/modules/compute/virtual_machine_extensions/main.tf @@ -22,4 +22,20 @@ data "azurecaf_environment_variable" "token" { name = var.extension.pats_from_env_variable.variable_name fails_if_empty = true +} + +locals { + module_tag = { + "module" = basename(abspath(path.module)) + } + tags = var.base_tags ? merge( + var.global_settings.tags, + try(var.resource_group.tags, null), + local.module_tag, + try(var.settings.tags, null) + ) : merge( + local.module_tag, + try(var.settings.tags, + null) + ) } \ No newline at end of file diff --git a/modules/compute/virtual_machine_extensions/microsoft.azure.diagnostics.tf b/modules/compute/virtual_machine_extensions/microsoft.azure.diagnostics.tf index 3c542e8427..7cdac3e2f4 100644 --- a/modules/compute/virtual_machine_extensions/microsoft.azure.diagnostics.tf +++ b/modules/compute/virtual_machine_extensions/microsoft.azure.diagnostics.tf @@ -9,6 +9,7 @@ resource "azurerm_virtual_machine_extension" "diagnostics" { type = "IaaSDiagnostics" type_handler_version = try(var.extension.type_handler_version, "1.9") auto_upgrade_minor_version = try(var.extension.auto_upgrade_minor_version, true) + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode( { diff --git a/modules/compute/virtual_machine_extensions/tfcloud_selfhosted_agent.tf b/modules/compute/virtual_machine_extensions/tfcloud_selfhosted_agent.tf index 3ed0b5e730..7b7535637a 100644 --- a/modules/compute/virtual_machine_extensions/tfcloud_selfhosted_agent.tf +++ b/modules/compute/virtual_machine_extensions/tfcloud_selfhosted_agent.tf @@ -19,6 +19,7 @@ resource "azurerm_virtual_machine_extension" "tfcloud_selfhosted_agent" { publisher = "Microsoft.Azure.Extensions" type = "CustomScript" type_handler_version = "2.1" + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode(local.tfcloud_selfhosted_agent_settings) protected_settings = jsonencode(local.tfcloud_selfhosted_agent_protected_settings) diff --git a/modules/compute/virtual_machine_extensions/variables.tf b/modules/compute/virtual_machine_extensions/variables.tf index 2fa1024ff5..2a53344bab 100644 --- a/modules/compute/virtual_machine_extensions/variables.tf +++ b/modules/compute/virtual_machine_extensions/variables.tf @@ -24,4 +24,14 @@ variable "storage_accounts" { } variable "virtual_machine_os_type" { default = {} -} \ No newline at end of file +} +variable "base_tags" { + description = "Base tags for the resource to be inherited from the resource group." + type = bool +} +variable "global_settings" { + description = "Global settings object (see module README.md)" +} +variable "resource_group" { + description = "Resource group object to deploy the virtual machine" +} diff --git a/modules/compute/virtual_machine_extensions/wvd_dsc.tf b/modules/compute/virtual_machine_extensions/wvd_dsc.tf index ee5e430d4c..71dde0f943 100644 --- a/modules/compute/virtual_machine_extensions/wvd_dsc.tf +++ b/modules/compute/virtual_machine_extensions/wvd_dsc.tf @@ -6,6 +6,7 @@ resource "azurerm_virtual_machine_extension" "session_host_dscextension" { type = "DSC" type_handler_version = "2.73" auto_upgrade_minor_version = true + tags = merge(local.tags, try(each.value.tags, null)) settings = jsonencode( { diff --git a/modules/logic_app/standard/main.tf b/modules/logic_app/standard/main.tf index 24d628edd4..813de642d3 100644 --- a/modules/logic_app/standard/main.tf +++ b/modules/logic_app/standard/main.tf @@ -7,7 +7,21 @@ terraform { } locals { - resource_group = var.resource_groups[try(var.settings.lz_key, var.settings.resource_group.lz_key, var.client_config.landingzone_key)][try(var.settings.resource_group.key, var.settings.resource_group_key)] + module_tag = { + "module" = basename(abspath(path.module)) + } + tags = var.base_tags ? merge( + var.global_settings.tags, + try(var.resource_group.tags, null), + local.module_tag, + try(var.tags, null) + ) : merge( + local.module_tag, + try(var.tags, + null) + ) + location = coalesce(var.location, var.resource_group.location) + resource_group_name = coalesce(var.resource_group_name, var.resource_group.name) storage_account = var.storage_accounts[try(var.settings.lz_key, var.settings.storage_account.lz_key, var.client_config.landingzone_key)][try(var.settings.storage_account.key, var.settings.storage_account_key)] app_service_plan = var.app_service_plans[try(var.settings.app_service_plan.lz_key, var.settings.lz_key, var.client_config.landingzone_key)][try(var.settings.app_service_plan.key, var.settings.app_service_plan_key)] app_settings = var.external_app_settings == true ? null : try(var.app_settings, null) diff --git a/modules/logic_app/standard/module.tf b/modules/logic_app/standard/module.tf index ad6d9e1d86..73cd8ee567 100644 --- a/modules/logic_app/standard/module.tf +++ b/modules/logic_app/standard/module.tf @@ -10,12 +10,13 @@ resource "azurecaf_name" "logic_app_standard_name" { resource "azurerm_logic_app_standard" "logic_app_standard" { name = azurecaf_name.logic_app_standard_name.result - location = lookup(var.settings, "region", null) == null ? local.resource_group.location : var.global_settings.regions[var.settings.region] - resource_group_name = local.resource_group.name + location = local.location + resource_group_name = local.resource_group_name app_service_plan_id = local.app_service_plan.id storage_account_name = local.storage_account.name storage_account_access_key = local.storage_account.primary_access_key https_only = try(var.settings.https_only, null) + tags = merge(local.tags, try(var.settings.tags, {})) app_settings = local.app_settings @@ -64,4 +65,4 @@ resource "azurerm_app_service_virtual_network_swift_connection" "vnet_config" { app_service_id = azurerm_logic_app_standard.logic_app_standard.id subnet_id = can(var.vnet_integration.subnet_id) ? var.vnet_integration.subnet_id : try(var.vnets[try(var.vnet_integration.lz_key, var.client_config.landingzone_key)][var.vnet_integration.vnet_key].subnets[var.vnet_integration.subnet_key].id, try(var.virtual_subnets[var.client_config.landingzone_key][var.vnet_integration.subnet_key].id, var.virtual_subnets[var.vnet_integration.lz_key][var.vnet_integration.subnet_key].id)) -} \ No newline at end of file +} diff --git a/modules/logic_app/standard/private_endpoint.tf b/modules/logic_app/standard/private_endpoint.tf index d46c41e327..a1a8e4b816 100644 --- a/modules/logic_app/standard/private_endpoint.tf +++ b/modules/logic_app/standard/private_endpoint.tf @@ -4,8 +4,8 @@ module "private_endpoint" { resource_id = azurerm_logic_app_standard.logic_app_standard.id name = each.value.name - location = lookup(var.settings, "region", null) == null ? local.resource_group.location : var.global_settings.regions[var.settings.region] - resource_group_name = local.resource_group.name + location = local.location + resource_group_name = local.resource_group_name subnet_id = coalesce( try(each.value.subnet_id, null), try(var.vnets[var.client_config.landingzone_key][each.value.vnet_key].subnets[each.value.subnet_key].id, null), diff --git a/modules/logic_app/standard/variables.tf b/modules/logic_app/standard/variables.tf index 9256d53e8d..715c976dc4 100644 --- a/modules/logic_app/standard/variables.tf +++ b/modules/logic_app/standard/variables.tf @@ -52,4 +52,22 @@ variable "external_app_settings" { variable "dynamic_app_settings" { default = {} +} + +variable "resource_group" { + description = "Resource group object to deploy the virtual machine" +} + +variable "tags" { + default = null +} + +variable "resource_group_name" { + description = "Resource group object to deploy the virtual machine" + default = null +} + +variable "location" { + description = "(Required) Resource Location" + default = null } \ No newline at end of file diff --git a/virtual_machines_extensions.tf b/virtual_machines_extensions.tf index 9a55ee90f8..4642d830ff 100644 --- a/virtual_machines_extensions.tf +++ b/virtual_machines_extensions.tf @@ -14,6 +14,9 @@ module "vm_extension_monitoring_agent" { virtual_machine_id = module.virtual_machines[each.key].id extension = each.value.virtual_machine_extensions.microsoft_enterprise_cloud_monitoring extension_name = "microsoft_enterprise_cloud_monitoring" + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] settings = { diagnostics = local.combined_diagnostics } @@ -31,6 +34,9 @@ module "vm_extension_diagnostics" { virtual_machine_id = module.virtual_machines[each.key].id extension = each.value.virtual_machine_extensions.microsoft_azure_diagnostics extension_name = "microsoft_azure_diagnostics" + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] settings = { var_folder_path = var.var_folder_path diagnostics = local.combined_diagnostics @@ -52,6 +58,9 @@ module "vm_extension_microsoft_azure_domainjoin" { extension = each.value.virtual_machine_extensions.microsoft_azure_domainjoin extension_name = "microsoft_azure_domainJoin" keyvaults = local.combined_objects_keyvaults + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] } module "vm_extension_session_host_dscextension" { @@ -69,6 +78,9 @@ module "vm_extension_session_host_dscextension" { extension_name = "session_host_dscextension" keyvaults = local.combined_objects_keyvaults wvd_host_pools = local.combined_objects_wvd_host_pools + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] } module "vm_extension_custom_scriptextension" { @@ -88,6 +100,9 @@ module "vm_extension_custom_scriptextension" { extension_name = "custom_script" managed_identities = local.combined_objects_managed_identities storage_accounts = local.combined_objects_storage_accounts + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] } module "vm_extension_generic" { @@ -102,6 +117,9 @@ module "vm_extension_generic" { virtual_machine_os_type = module.virtual_machines[each.key].os_type extension = each.value.virtual_machine_extensions.generic_extensions extension_name = "generic_extension" + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] } module "keyvault_for_windows" { @@ -119,6 +137,9 @@ module "keyvault_for_windows" { extension = each.value.virtual_machine_extensions.keyvault_for_windows extension_name = "keyvault_for_windows" keyvaults = local.combined_objects_keyvaults + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] } module "vm_extension_linux_diagnostic" { @@ -133,6 +154,9 @@ module "vm_extension_linux_diagnostic" { virtual_machine_id = module.virtual_machines[each.key].id extension = each.value.virtual_machine_extensions.linux_diagnostic extension_name = "linux_diagnostic" + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] settings = { var_folder_path = var.var_folder_path @@ -153,6 +177,9 @@ module "vm_extensions_devops_selfhosted_agent" { virtual_machine_id = module.virtual_machines[each.key].id extension = each.value.virtual_machine_extensions.devops_selfhosted_agent extension_name = "devops_selfhosted_agent" + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] settings = { devops_selfhosted_agent = { @@ -181,6 +208,9 @@ module "vm_extensions_tfcloud_selfhosted_agent" { virtual_machine_id = module.virtual_machines[each.key].id extension = each.value.virtual_machine_extensions.tfcloud_selfhosted_agent extension_name = "tfcloud_selfhosted_agent" + base_tags = local.global_settings.inherit_tags + global_settings = local.global_settings + resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group.key, each.value.resource_group_key)] settings = { tfcloud_selfhosted_agent = {