generated from Azure/terraform-azurerm-avm-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
124 lines (98 loc) · 3.57 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
terraform {
required_version = "~> 1.5"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.71"
}
random = {
source = "hashicorp/random"
version = "~> 3.6"
}
}
}
provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
locals {
prefix = "diag"
skus = ["Basic", "Standard", "Premium"]
}
module "regions" {
source = "Azure/regions/azurerm"
version = ">= 0.3.0"
recommended_regions_only = true
}
resource "random_integer" "region_index" {
max = length(module.regions.regions) - 1
min = 0
}
module "naming" {
source = "Azure/naming/azurerm"
version = ">= 0.3.0"
}
resource "azurerm_resource_group" "example" {
name = "${module.naming.resource_group.name_unique}-${local.prefix}"
location = "westeurope" # This test case in Premium SKU is not supported in some of the recommended regions. Pinned to an specific one to make the test more reliable. #module.regions.regions[random_integer.region_index.result].name
}
resource "azurerm_storage_account" "example" {
name = "${module.naming.storage_account.name_unique}${local.prefix}"
account_replication_type = "ZRS"
account_tier = "Standard"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
}
resource "azurerm_log_analytics_workspace" "example" {
name = "${module.naming.log_analytics_workspace.name_unique}-${local.prefix}"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
}
resource "azurerm_eventhub_namespace" "example" {
name = "${module.naming.eventhub_namespace.name_unique}-${local.prefix}"
sku = "Basic"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
}
resource "azurerm_eventhub" "example" {
name = "diagnosticshub"
partition_count = 2
message_retention = 1
resource_group_name = azurerm_resource_group.example.name
namespace_name = azurerm_eventhub_namespace.example.name
}
module "servicebus" {
source = "../../"
for_each = toset(local.skus)
sku = each.value
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
name = "${module.naming.servicebus_namespace.name_unique}-${each.value}-${local.prefix}"
diagnostic_settings = {
diagnostic1 = {
log_groups = ["allLogs"]
metric_groups = ["AllMetrics"]
name = "diagtest1"
log_analytics_destination_type = "Dedicated"
workspace_resource_id = azurerm_log_analytics_workspace.example.id
}
diagnostic2 = {
log_groups = ["audit"]
metric_groups = ["AllMetrics"]
name = "diagtest2"
log_analytics_destination_type = "Dedicated"
event_hub_name = azurerm_eventhub.example.name
event_hub_authorization_rule_resource_id = "${azurerm_eventhub_namespace.example.id}/authorizationRules/RootManageSharedAccessKey"
}
diagnostic3 = {
log_categories = ["ApplicationMetricsLogs", "RuntimeAuditLogs", "VNetAndIPFilteringLogs", "OperationalLogs"]
metric_groups = ["AllMetrics"]
name = "diagtest3"
log_analytics_destination_type = "Dedicated"
storage_account_resource_id = azurerm_storage_account.example.id
}
}
}