Skip to content

Commit

Permalink
Fixed eventgrid_system_topic location
Browse files Browse the repository at this point in the history
Fixed azurerm_eventgrid_system_topic_event_subscription
Added example eventgrid_system_event_subscription
Merge combined_objects_function_apps (module.function_apps and module.windows_function_apps)
  • Loading branch information
kevindelmont committed Sep 11, 2024
1 parent d1c6e09 commit 94d0554
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 45 deletions.
8 changes: 2 additions & 6 deletions eventgrid.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ module "eventgrid_event_subscription" {
output "eventgrid_event_subscription" {
value = module.eventgrid_event_subscription
}

module "eventgrid_domain_topic" {
source = "./modules/messaging/eventgrid/eventgrid_domain_topic"
for_each = local.messaging.eventgrid_domain_topic
Expand All @@ -77,7 +76,6 @@ module "eventgrid_domain_topic" {
output "eventgrid_domain_topic" {
value = module.eventgrid_domain_topic
}

module "eventgrid_system_topic" {
source = "./modules/messaging/eventgrid/eventgrid_system_topic"
for_each = local.messaging.eventgrid_system_topic
Expand All @@ -86,10 +84,8 @@ module "eventgrid_system_topic" {
client_config = local.client_config
settings = each.value
base_tags = try(local.global_settings.inherit_tags, false) ? try(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)].tags, {}) : {}

location = can(local.global_settings.regions[each.value.region]) ? local.global_settings.regions[each.value.region] : 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)].location

remote_objects = local.remote_objects
location = lookup(each.value, "region", null) != null ? each.value.region : can(local.global_settings.regions[each.value.region]) ? local.global_settings.regions[each.value.region] : 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)].location
remote_objects = local.remote_objects
}
output "eventgrid_system_topic" {
value = module.eventgrid_system_topic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
global_settings = {
default_region = "region1"
regions = {
region1 = "southeastasia"
}
}

resource_groups = {
evg_examples = {
name = "eventgrid"
region = "region1"
}
}

eventgrid_system_topic = {
egt1 = {
name = "egt1"
region = "global" # set global when topic_type = "Microsoft.Resources.Subscriptions"
resource_group = {
key = "evg_examples"
}
topic_type = "Microsoft.Resources.Subscriptions"
source_resource_id = "/subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333"
}
}

## Uncomment this part after deployed function on Azure Function
# eventgrid_system_event_subscription = {
# egs1 = {
# name = "egs1"
# resource_group = {
# key = "evg_examples"
# }
# eventgrid_system_topic = {
# key = "egt1"
# }
# event_delivery_schema = "EventGridSchema"
# included_event_types = ["Microsoft.Resources.ResourceWriteSuccess"]
# azure_function_endpoint = {
# function_name = "FunctionName" #Set function name after deployed it
# function_app = {
# key = "evg_examples"
# }
# }
# advanced_filtering_on_arrays_enabled = true
# advanced_filters = {
# string_not_in = [
# {
# key = "data.operationName"
# value = ["Microsoft.Resources/tags/write"]
# }
# ]
# }
# }
# }



5 changes: 3 additions & 2 deletions locals.combined_objects.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ locals {
combined_objects_express_route_circuit_peerings = merge(tomap({ (local.client_config.landingzone_key) = module.express_route_circuit_peerings }), lookup(var.remote_objects, "express_route_circuit_peerings", {}))
combined_objects_express_route_circuits = merge(tomap({ (local.client_config.landingzone_key) = module.express_route_circuits }), lookup(var.remote_objects, "express_route_circuits", {}), lookup(var.data_sources, "express_route_circuits", {}))
combined_objects_front_door = merge(tomap({ (local.client_config.landingzone_key) = module.front_doors }), lookup(var.remote_objects, "front_doors", {}))
combined_objects_front_door_waf_policies = merge(tomap({ (local.client_config.landingzone_key) = module.front_door_waf_policies }), lookup(var.remote_objects, "front_door_waf_policies", {}))
combined_objects_function_apps = merge(tomap({ (local.client_config.landingzone_key) = module.function_apps }), lookup(var.remote_objects, "function_apps", {}))
combined_objects_front_door_waf_policies = merge(tomap({ (local.client_config.landingzone_key) = module.front_door_waf_policies }), lookup(var.remote_objects, "front_door_waf_policies", {}))
combined_objects_function_apps = merge(tomap({ (local.client_config.landingzone_key) = merge(module.function_apps, module.windows_function_apps) }), lookup(var.remote_objects, "function_apps", {}), lookup(var.remote_objects, "windows_function_apps", {}))
combined_objects_image_definitions = merge(tomap({ (local.client_config.landingzone_key) = module.image_definitions }), lookup(var.remote_objects, "image_definitions", {}))
combined_objects_integration_service_environment = merge(tomap({ (local.client_config.landingzone_key) = module.integration_service_environment }), lookup(var.remote_objects, "integration_service_environment", {}))
combined_objects_iot_central_application = merge(tomap({ (local.client_config.landingzone_key) = module.iot_central_application }), lookup(var.remote_objects, "iot_central_application", {}))
Expand Down Expand Up @@ -170,6 +170,7 @@ locals {
combined_objects_virtual_hubs = merge(tomap({ (local.client_config.landingzone_key) = merge(module.virtual_hubs, lookup(var.data_sources, "virtual_hubs", {})) }), lookup(var.remote_objects, "virtual_hubs", {}), lookup(var.data_sources, "virtual_hubs", {}))
combined_objects_virtual_machine_scale_sets = merge(tomap({ (local.client_config.landingzone_key) = module.virtual_machine_scale_sets }), lookup(var.remote_objects, "virtual_machine_scale_sets", {}), lookup(var.data_sources, "virtual_machine_scale_sets", {}))
combined_objects_virtual_machines = merge(tomap({ (local.client_config.landingzone_key) = module.virtual_machines }), lookup(var.remote_objects, "virtual_machines", {}), lookup(var.data_sources, "virtual_machines", {}))
combined_objects_virtual_machines_replication = merge(tomap({ (local.client_config.landingzone_key) = module.vm_replication }), try(var.remote_objects.virtual_machines_replication, {}), try(var.data_sources.virtual_machines_replication, {}))
combined_objects_virtual_subnets = merge(tomap({ (local.client_config.landingzone_key) = merge(module.virtual_subnets, lookup(var.data_sources, "virtual_subnets", {})) }), lookup(var.remote_objects, "virtual_subnets", {}))
combined_objects_vmware_clusters = merge(tomap({ (local.client_config.landingzone_key) = module.vmware_clusters }), lookup(var.remote_objects, "vmware_clusters", {}))
combined_objects_vmware_express_route_authorizations = merge(tomap({ (local.client_config.landingzone_key) = module.vmware_express_route_authorizations }), lookup(var.remote_objects, "vmware_express_route_authorizations", {}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,140 +47,147 @@ resource "azurerm_eventgrid_system_topic_event_subscription" "eges" {
}
}
included_event_types = try(var.settings.included_event_types, null)

dynamic "subject_filter" {
for_each = try(var.settings.subject_filter, null) != null ? [var.settings.subject_filter] : []
content {
subject_begins_with = try(subject_filter.value.subject_begins_with, null)
subject_ends_with = try(subject_filter.value.subject_ends_with, null)
case_sensitive = try(subject_filter.value.case_sensitive, null)
}
}
dynamic "advanced_filter" {
for_each = try(var.settings.advanced_filter, null) != null ? [var.settings.advanced_filter] : []
content {
dynamic "bool_equals" {
for_each = try(var.settings.bool_equals, null) != null ? [var.settings.bool_equals] : []
content {
key = try(bool_equals.value.subject_begins_with, null)
value = try(bool_equals.value.subject_ends_with, null)
key = try(bool_equals.value.key, null)
value = try(bool_equals.value.value, null)
}
}
dynamic "number_greater_than" {
for_each = try(var.settings.number_greater_than, null) != null ? [var.settings.number_greater_than] : []
content {
key = try(number_greater_than.value.subject_begins_with, null)
value = try(number_greater_than.value.subject_ends_with, null)
key = try(number_greater_than.value.key, null)
value = try(number_greater_than.value.value, null)

}
}
dynamic "number_greater_than_or_equals" {
for_each = try(var.settings.number_greater_than_or_equals, null) != null ? [var.settings.number_greater_than_or_equals] : []
content {
key = try(number_greater_than_or_equals.value.subject_begins_with, null)
value = try(number_greater_than_or_equals.value.subject_ends_with, null)
key = try(number_greater_than_or_equals.value.key, null)
value = try(number_greater_than_or_equals.value.value, null)
}
}
dynamic "number_less_than" {
for_each = try(var.settings.number_less_than, null) != null ? [var.settings.number_less_than] : []
content {
key = try(number_less_than.value.subject_begins_with, null)
value = try(number_less_than.value.subject_ends_with, null)
key = try(number_less_than.value.key, null)
value = try(number_less_than.value.value, null)
}
}
dynamic "number_less_than_or_equals" {
for_each = try(var.settings.number_less_than_or_equals, null) != null ? [var.settings.number_less_than_or_equals] : []
content {
key = try(number_less_than.value.number_less_than_or_equals, null)
value = try(number_less_than.value.number_less_than_or_equals, null)
key = try(number_less_than_or_equals.value.key, null)
value = try(number_less_than_or_equals.value.value, null)
}
}
dynamic "number_in" {
for_each = try(var.settings.number_in, null) != null ? [var.settings.number_in] : []
content {
key = try(number_less_than.value.number_in, null)
values = try(number_less_than.value.number_in, null)
key = try(number_in.value.key, null)
values = try(number_in.value.values, null)
}
}
dynamic "number_not_in" {
for_each = try(var.settings.number_not_in, null) != null ? [var.settings.number_not_in] : []
content {
key = try(number_less_than.value.number_not_in, null)
values = try(number_less_than.value.number_not_in, null)
key = try(number_not_in.value.key, null)
values = try(number_not_in.value.values, null)
}
}
dynamic "number_in_range" {
for_each = try(var.settings.number_in_range, null) != null ? [var.settings.number_in_range] : []
content {
key = try(number_less_than.value.number_in_range, null)
values = try(number_less_than.value.number_in_range, null)
key = try(number_in_range.value.key, null)
values = try(number_in_range.value.values, null)
}
}
dynamic "number_not_in_range" {
for_each = try(var.settings.number_not_in_range, null) != null ? [var.settings.number_not_in_range] : []
content {
key = try(number_less_than.value.number_not_in_range, null)
values = try(number_less_than.value.number_not_in_range, null)
key = try(number_not_in_range.value.key, null)
values = try(number_not_in_range.value.values, null)
}
}
dynamic "string_begins_with" {
for_each = try(var.settings.string_begins_with, null) != null ? [var.settings.string_begins_with] : []
content {
key = try(number_less_than.value.string_begins_with, null)
values = try(number_less_than.value.string_begins_with, null)
key = try(string_begins_with.value.key, null)
values = try(string_begins_with.value.values, null)
}
}
dynamic "string_not_begins_with" {
for_each = try(var.settings.string_not_begins_with, null) != null ? [var.settings.string_not_begins_with] : []
content {
key = try(number_less_than.value.string_not_begins_with, null)
values = try(number_less_than.value.string_not_begins_with, null)
key = try(string_not_begins_with.value.key, null)
values = try(string_not_begins_with.value.values, null)
}
}
dynamic "string_ends_with" {
for_each = try(var.settings.string_ends_with, null) != null ? [var.settings.string_ends_with] : []
content {
key = try(number_less_than.value.string_ends_with, null)
values = try(number_less_than.value.string_ends_with, null)
key = try(string_ends_with.value.key, null)
values = try(string_ends_with.value.values, null)
}
}
dynamic "string_not_ends_with" {
for_each = try(var.settings.string_not_ends_with, null) != null ? [var.settings.string_not_ends_with] : []
content {
key = try(number_less_than.value.string_not_ends_with, null)
values = try(number_less_than.value.string_not_ends_with, null)
key = try(string_not_ends_with.value.key, null)
values = try(string_not_ends_with.value.values, null)
}
}
dynamic "string_contains" {
for_each = try(var.settings.string_contains, null) != null ? [var.settings.string_contains] : []
content {
key = try(number_less_than.value.string_contains, null)
values = try(number_less_than.value.string_contains, null)
key = try(string_contains.value.key, null)
values = try(string_contains.value.values, null)
}
}
dynamic "string_not_contains" {
for_each = try(var.settings.string_not_contains, null) != null ? [var.settings.string_not_contains] : []
content {
key = try(number_less_than.value.string_not_contains, null)
values = try(number_less_than.value.string_not_contains, null)
key = try(string_not_contains.value.key, null)
values = try(string_not_contains.value.values, null)
}
}
dynamic "string_in" {
for_each = try(var.settings.string_in, null) != null ? [var.settings.string_in] : []
content {
key = try(number_less_than.value.string_in, null)
values = try(number_less_than.value.string_in, null)
key = try(string_in.value.key, null)
values = try(string_in.value.values, null)
}
}
dynamic "string_not_in" {
for_each = try(var.settings.string_not_in, null) != null ? [var.settings.string_not_in] : []
content {
key = try(number_less_than.value.string_not_in, null)
values = try(number_less_than.value.string_not_in, null)
key = try(string_not_in.value.key, null)
values = try(string_not_in.value.values, null)
}
}
dynamic "is_not_null" {
for_each = try(var.settings.is_not_null, null) != null ? [var.settings.is_not_null] : []
content {
key = try(number_less_than.value.is_not_null, null)
key = try(is_not_null.value.key, null)
}
}
dynamic "is_null_or_undefined" {
for_each = try(var.settings.is_null_or_undefined, null) != null ? [var.settings.is_null_or_undefined] : []
content {
key = try(number_less_than.value.is_null_or_undefined, null)
key = try(is_null_or_undefined.value.key, null)
}
}
}
Expand Down

0 comments on commit 94d0554

Please sign in to comment.