Skip to content

claranet/terraform-azurerm-eventgrid

Repository files navigation

Azure Event Grid

Changelog Notice Apache V2 License TF Registry

This Terraform module creates an Azure Eventgrid system topic with an Azure Eventgrid system topic event subscription and activated Diagnostics Logs.

You can create an Azure Eventgrid system topic event subscription without Eventgrid system topic by using the submodule modules/event-subscription.

Global versioning rule for Claranet Azure modules

Module version Terraform version AzureRM version
>= 7.x.x 1.3.x >= 3.0
>= 6.x.x 1.x >= 3.0
>= 5.x.x 0.15.x >= 2.0
>= 4.x.x 0.13.x / 0.14.x >= 2.0
>= 3.x.x 0.12.x >= 2.0
>= 2.x.x 0.12.x < 2.0
< 2.x.x 0.11.x < 2.0

Contributing

If you want to contribute to this repository, feel free to use our pre-commit git hook configuration which will help you automatically update and format some files for you by enforcing our Terraform code module best-practices.

More details are available in the CONTRIBUTING.md file.

Usage

This module is optimized to work with the Claranet terraform-wrapper tool which set some terraform variables in the environment needed by this module. More details about variables set by the terraform-wrapper available in the documentation.

module "region" {
  source  = "claranet/regions/azurerm"
  version = "x.x.x"

  azure_region = var.azure_region
}

module "rg" {
  source  = "claranet/rg/azurerm"
  version = "x.x.x"

  location    = module.region.location
  client_name = var.client_name
  environment = var.environment
  stack       = var.stack
}

module "logs" {
  source  = "claranet/run/azurerm//modules/logs"
  version = "x.x.x"

  resource_group_name = module.rg.resource_group_name
  stack               = var.stack
  environment         = var.environment
  client_name         = var.client_name
  location            = module.region.location
  location_short      = module.region.location_short
}


data "azurerm_client_config" "current" {
}

module "keyvault" {
  source  = "claranet/keyvault/azurerm"
  version = "x.x.x"

  resource_group_name = module.rg.resource_group_name
  stack               = var.stack
  environment         = var.environment
  client_name         = var.client_name
  location            = module.region.location
  location_short      = module.region.location_short

  logs_destinations_ids = [
    module.logs.logs_storage_account_id,
    module.logs.log_analytics_workspace_id,
  ]

  admin_objects_ids = [
    data.azurerm_client_config.current.object_id
  ]
}


resource "azurerm_storage_account" "storage_acount" {
  name                     = "examplestorageacc"
  resource_group_name      = module.rg.resource_group_name
  location                 = module.region.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
  min_tls_version          = "TLS1_2"

  queue_properties {
    logging {
      delete                = true
      read                  = true
      write                 = true
      version               = "1.0"
      retention_policy_days = 10
    }
  }
}

resource "azurerm_storage_queue" "storage_queue" {
  name                 = "mysamplequeue"
  storage_account_name = azurerm_storage_account.storage_acount.name
}

module "eventgrid" {
  source  = "claranet/eventgrid/azurerm"
  version = "x.x.x"

  resource_group_name = module.rg.resource_group_name
  stack               = var.stack
  environment         = var.environment
  client_name         = var.client_name
  location            = module.region.location
  location_short      = module.region.location_short

  source_resource_id = module.keyvault.key_vault_id

  storage_queue_endpoint = {
    storage_account_id = azurerm_storage_account.storage_acount.id
    queue_name         = azurerm_storage_queue.storage_queue.name
  }

  logs_destinations_ids = [
    module.logs.logs_storage_account_id,
    module.logs.log_analytics_workspace_id
  ]
}

Providers

Name Version
azurecaf ~> 1.2, >= 1.2.22
azurerm ~> 3.39

Modules

Name Source Version
diagnostics claranet/diagnostic-settings/azurerm ~> 6.5.0
event_subscription ./modules/event-subscription n/a

Resources

Name Type
azurerm_eventgrid_system_topic.eventgrid_system_topic resource
azurecaf_name.eventgrid data source

Inputs

Name Description Type Default Required
advanced_filter Filter a value of an event for an Event Subscription based on a condition.
object({
bool_equals = optional(object({
key = string
value = bool
}), null)
number_greater_than = optional(object({
key = string
value = number
}), null)
number_greater_than_or_equals = optional(object({
key = string
value = number
}), null)
number_less_than = optional(object({
key = string
value = number
}), null)
number_less_than_or_equals = optional(object({
key = string
value = number
}), null)
number_in = optional(object({
key = string
values = list(number)
}), null)
number_not_in = optional(object({
key = string
values = list(number)
}), null)
string_begins_with = optional(object({
key = string
values = list(string)
}), null)
string_not_begins_with = optional(object({
key = string
values = list(string)
}), null)
string_ends_with = optional(object({
key = string
values = list(string)
}), null)
string_not_ends_with = optional(object({
key = string
values = list(string)
}), null)
string_contains = optional(object({
key = string
values = list(string)
}), null)
string_not_contains = optional(object({
key = string
values = list(string)
}), null)
string_in = optional(object({
key = string
values = list(string)
}), null)
string_not_in = optional(object({
key = string
values = list(string)
}), null)
is_not_null = optional(object({
key = string
}), null)
is_null_or_undefined = optional(object({
key = string
}), null)
})
null no
advanced_filtering_on_arrays_enabled Specifies whether advanced filters should be evaluated against an array of values instead of expecting a singular value. bool null no
azure_function_endpoint Function where the Event Subscription will receive events.
object({
function_id = string
max_events_per_batch = optional(number)
preferred_batch_size_in_kilobytes = optional(number)
})
null no
client_name Client name/account used in naming. string n/a yes
custom_diagnostic_settings_name Custom name of the diagnostics settings, name will be 'default' if not set. string "default" no
custom_name Custom Azure Eventgrid name, generated if not set string "" no
default_tags_enabled Option to enable or disable default tags. bool true no
delivery_property Option to set custom headers on delivered events.
list(object({
header_name = string
type = string
value = optional(string)
source_field = optional(string)
secret = optional(bool)
}))
[] no
environment Project environment. string n/a yes
event_delivery_schema Specifies the event delivery schema for the Event Subscription. Possible values include: EventGridSchema, CloudEventSchemaV1_0, CustomInputSchema. string "EventGridSchema" no
event_subscription_custom_name Event subscription optional custom name string "" no
eventhub_endpoint_id ID of the Event Hub where the Event subscription will receive events. string null no
expiration_time_utc Specifies the expiration time of the Event Subscription (Datetime Format RFC 3339). string null no
extra_tags Additional tags to associate with your Azure Eventgrid. map(string) {} no
hybrid_connection_endpoint_id ID of the Hybrid Connection where the Event subscription will receive events. string null no
included_event_types List of applicable event types that need to be part of the Event Subscription. list(string) [] no
labels List of labels to assign to the Event Subscription. list(string) [] no
location Azure location. string n/a yes
location_short Short string for Azure location. string n/a yes
logs_categories Log categories to send to destinations. list(string) null no
logs_destinations_ids List of destination resources IDs for logs diagnostic destination.
Can be Storage Account, Log Analytics Workspace and Event Hub. No more than one of each can be set.
If you want to specify an Azure EventHub to send logs and metrics to, you need to provide a formated string with both the EventHub Namespace authorization send ID and the EventHub name (name of the queue to use in the Namespace) separated by the `
` character. list(string) n/a
logs_metrics_categories Metrics categories to send to destinations. list(string) null no
name_prefix Optional prefix for the generated name string "" no
name_suffix Optional suffix for the generated name string "" no
resource_group_name Resource Group name. string n/a yes
retry_policy Delivery retry attempts for events.
object({
max_delivery_attempts = number
event_time_to_live = number
})
null no
service_bus_queue_endpoint_id ID of the Service Bus Queue where the Event subscription will receive events. string null no
service_bus_topic_endpoint_id ID of the Service Bus Topic where the Event subscription will receive events. string null no
source_resource_id ID of the Event Grid System Topic ARM Source. string n/a yes
stack Project Stack name. string n/a yes
storage_blob_dead_letter_destination Storage blob container that is the destination of the deadletter events.
object({
storage_account_id = string
storage_blob_container_name = string
})
null no
storage_queue_endpoint Storage Queue endpoint block configuration where the Event subscription will receive events.
object({
storage_account_id = string
queue_name = string
queue_message_time_to_live_in_seconds = optional(number)
})
null no
subject_filter Block to filter events for an Event Subscription based on a resource path prefix or suffix.
object({
subject_begins_with = optional(string)
subject_ends_with = optional(string)
case_sensitive = optional(bool)
})
null no
use_caf_naming Use the Azure CAF naming provider to generate default resource name. custom_name override this if set. Legacy default name is used if this is set to false. bool true no
webhook_endpoint Webhook configuration block where the Event Subscription will receive events.
object({
url = string
base_url = optional(string)
max_events_per_batch = optional(number)
preferred_batch_size_in_kilobytes = optional(number)
active_directory_tenant_id = optional(string)
active_directory_app_id_or_uri = optional(string)
})
null no

Outputs

Name Description
id Azure Event Grid System Topic ID
identity_principal_id Azure Event Grid System Topic identity's principal ID
metric_arm_resource_id Azure Event Grid System Topic's metric ARM resource ID
name Azure Event Grid System Topic name