-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
164 lines (141 loc) · 6.6 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
resource "azurerm_postgresql_flexible_server" "this" {
location = var.location
name = var.name
resource_group_name = var.resource_group_name
administrator_login = var.administrator_login
administrator_password = var.administrator_password
auto_grow_enabled = var.auto_grow_enabled
backup_retention_days = var.backup_retention_days
create_mode = var.create_mode
delegated_subnet_id = var.delegated_subnet_id
geo_redundant_backup_enabled = var.geo_redundant_backup_enabled
point_in_time_restore_time_in_utc = var.point_in_time_restore_time_in_utc
private_dns_zone_id = var.private_dns_zone_id
public_network_access_enabled = var.public_network_access_enabled
replication_role = var.replication_role
sku_name = var.sku_name
source_server_id = var.source_server_id
storage_mb = var.storage_mb
storage_tier = var.storage_tier
tags = var.tags
version = var.server_version
zone = var.zone
dynamic "authentication" {
for_each = var.authentication == null ? [] : [var.authentication]
content {
active_directory_auth_enabled = authentication.value.active_directory_auth_enabled
password_auth_enabled = authentication.value.password_auth_enabled
tenant_id = authentication.value.tenant_id
}
}
dynamic "customer_managed_key" {
for_each = var.customer_managed_key == null ? [] : [var.customer_managed_key]
content {
key_vault_key_id = customer_managed_key.value.key_vault_key_id
geo_backup_key_vault_key_id = customer_managed_key.value.geo_backup_key_vault_key_id
geo_backup_user_assigned_identity_id = customer_managed_key.value.geo_backup_user_assigned_identity_id
primary_user_assigned_identity_id = customer_managed_key.value.primary_user_assigned_identity_id
}
}
dynamic "high_availability" {
for_each = var.high_availability == null ? [] : [var.high_availability]
content {
mode = high_availability.value.mode
standby_availability_zone = high_availability.value.standby_availability_zone
}
}
dynamic "identity" {
for_each = local.managed_identities.system_assigned_user_assigned
content {
identity_ids = identity.value.user_assigned_resource_ids
type = identity.value.type
}
}
dynamic "maintenance_window" {
for_each = var.maintenance_window == null ? [] : [var.maintenance_window]
content {
day_of_week = maintenance_window.value.day_of_week
start_hour = maintenance_window.value.start_hour
start_minute = maintenance_window.value.start_minute
}
}
dynamic "timeouts" {
for_each = var.timeouts == null ? [] : [var.timeouts]
content {
create = timeouts.value.create
delete = timeouts.value.delete
read = timeouts.value.read
update = timeouts.value.update
}
}
}
# required AVM resources interfaces
resource "azurerm_management_lock" "this" {
count = var.lock != null ? 1 : 0
lock_level = var.lock.kind
name = coalesce(var.lock.name, "lock-${var.lock.kind}")
scope = azurerm_postgresql_flexible_server.this.id
notes = var.lock.kind == "CanNotDelete" ? "Cannot delete the resource or its child resources." : "Cannot delete or modify the resource or its child resources."
}
resource "azurerm_role_assignment" "this" {
for_each = var.role_assignments
principal_id = each.value.principal_id
scope = azurerm_postgresql_flexible_server.this.id
condition = each.value.condition
condition_version = each.value.condition_version
delegated_managed_identity_resource_id = each.value.delegated_managed_identity_resource_id
role_definition_id = strcontains(lower(each.value.role_definition_id_or_name), lower(local.role_definition_resource_substring)) ? each.value.role_definition_id_or_name : null
role_definition_name = strcontains(lower(each.value.role_definition_id_or_name), lower(local.role_definition_resource_substring)) ? null : each.value.role_definition_id_or_name
skip_service_principal_aad_check = each.value.skip_service_principal_aad_check
}
resource "azurerm_monitor_diagnostic_setting" "this" {
for_each = var.diagnostic_settings
name = each.value.name != null ? each.value.name : "diag-${var.name}"
target_resource_id = azurerm_postgresql_flexible_server.this.id
eventhub_authorization_rule_id = each.value.event_hub_authorization_rule_resource_id
eventhub_name = each.value.event_hub_name
log_analytics_destination_type = each.value.log_analytics_destination_type
log_analytics_workspace_id = each.value.workspace_resource_id
partner_solution_id = each.value.marketplace_partner_resource_id
storage_account_id = each.value.storage_account_resource_id
dynamic "enabled_log" {
for_each = each.value.log_categories
content {
category = enabled_log.value
}
}
dynamic "enabled_log" {
for_each = each.value.log_groups
content {
category_group = enabled_log.value
}
}
dynamic "metric" {
for_each = each.value.metric_categories
content {
category = metric.value
}
}
}
resource "azurerm_postgresql_flexible_server_active_directory_administrator" "this" {
for_each = var.ad_administrator
object_id = each.value.data.object_id
principal_name = each.value.data.principal_name
principal_type = each.value.data.principal_type
resource_group_name = azurerm_postgresql_flexible_server.this.resource_group_name
server_name = azurerm_postgresql_flexible_server.this.name
tenant_id = each.value.data.tenant_id
}
resource "azurerm_postgresql_flexible_server_configuration" "this" {
for_each = var.server_configuration
name = each.value.name
server_id = azurerm_postgresql_flexible_server.this.id
value = each.value.config
}
resource "azurerm_postgresql_flexible_server_virtual_endpoint" "this" {
for_each = var.virtual_endpoint
name = each.value.name
replica_server_id = each.value.replica_server_id
source_server_id = azurerm_postgresql_flexible_server.this.id
type = each.value.type
}