Skip to content

Commit 3b05daf

Browse files
authored
Merge pull request #55 from AnkithaBH/cr-enhancement
Added enhancements
2 parents c804e97 + 106db40 commit 3b05daf

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

main.tf

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ resource "random_password" "main" {
4444

4545
resource "azurerm_mysql_flexible_server" "main" {
4646
count = var.enabled ? 1 : 0
47-
name = format("%s-mysql-flexible-server", module.labels.id)
47+
name = var.mysql_server_name != null ? var.mysql_server_name : format("%s-mysql-flexible-server", module.labels.id)
4848
resource_group_name = local.resource_group_name
4949
location = var.location
5050
administrator_login = var.admin_username
@@ -71,15 +71,35 @@ resource "azurerm_mysql_flexible_server" "main" {
7171
standby_availability_zone = lookup(high_availability.value, "standby_availability_zone", 1)
7272
}
7373
}
74+
identity {
75+
type = var.identity_type
76+
identity_ids = var.identity_type == "UserAssigned" ? var.user_assigned_identity_ids : []
77+
}
7478

7579
version = var.mysql_version
7680
zone = var.zone
7781

78-
tags = module.labels.tags
82+
tags = var.custom_tags == null ? module.labels.tags : var.custom_tags
7983

8084
depends_on = [azurerm_private_dns_zone_virtual_network_link.main, azurerm_private_dns_zone_virtual_network_link.main2]
8185
}
8286

87+
##-----------------------------------------------------------------------------
88+
## Below resource will create mysql server active directory administrator.
89+
##-----------------------------------------------------------------------------
90+
91+
resource "azurerm_mysql_flexible_server_active_directory_administrator" "main" {
92+
count = length(var.entra_authentication.object_id[*]) > 0 ? 1 : 0
93+
94+
server_id = join("", azurerm_mysql_flexible_server.main.*.id)
95+
identity_id = var.entra_authentication.user_assigned_identity_id
96+
login = var.entra_authentication.login
97+
object_id = var.entra_authentication.object_id
98+
tenant_id = data.azurerm_client_config.current.tenant_id
99+
100+
depends_on = [ azurerm_mysql_flexible_server.main ]
101+
}
102+
83103
##-----------------------------------------------------------------------------
84104
## Below resource will create mysql flexible database.
85105
##-----------------------------------------------------------------------------
@@ -91,7 +111,7 @@ resource "azurerm_mysql_flexible_database" "main" {
91111
server_name = join("", azurerm_mysql_flexible_server.main.*.name)
92112
charset = var.charset
93113
collation = var.collation
94-
depends_on = [azurerm_mysql_flexible_server.main]
114+
depends_on = [azurerm_mysql_flexible_server_active_directory_administrator.main]
95115
}
96116

97117
##-----------------------------------------------------------------------------
@@ -122,7 +142,7 @@ resource "azurerm_private_dns_zone" "main" {
122142
count = var.enabled && var.private_dns ? 1 : 0
123143
name = "privatelink.mysql.database.azure.com"
124144
resource_group_name = local.resource_group_name
125-
tags = module.labels.tags
145+
tags = var.custom_tags == null ? module.labels.tags : var.custom_tags
126146
}
127147

128148
##-----------------------------------------------------------------------------
@@ -135,7 +155,7 @@ resource "azurerm_private_dns_zone_virtual_network_link" "main" {
135155
virtual_network_id = var.virtual_network_id
136156
resource_group_name = local.resource_group_name
137157
registration_enabled = var.registration_enabled
138-
tags = module.labels.tags
158+
tags = var.custom_tags == null ? module.labels.tags : var.custom_tags
139159
}
140160

141161
##-----------------------------------------------------------------------------
@@ -148,7 +168,7 @@ resource "azurerm_private_dns_zone_virtual_network_link" "main2" {
148168
virtual_network_id = var.virtual_network_id
149169
resource_group_name = var.main_rg_name
150170
registration_enabled = var.registration_enabled
151-
tags = module.labels.tags
171+
tags = var.custom_tags == null ? module.labels.tags : var.custom_tags
152172
}
153173

154174
resource "azurerm_monitor_diagnostic_setting" "mysql" {

variables.tf

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,7 @@ variable "high_availability" {
245245
mode = string
246246
standby_availability_zone = optional(number)
247247
})
248-
default = {
249-
mode = "SameZone"
250-
standby_availability_zone = 1
251-
}
248+
default = null
252249
}
253250

254251
variable "enable_diagnostic" {
@@ -298,4 +295,31 @@ variable "eventhub_authorization_rule_id" {
298295
type = string
299296
default = null
300297
description = "Eventhub authorization rule id to pass it to destination details of diagnosys setting of NSG."
301-
}
298+
}
299+
300+
variable "custom_tags" {
301+
type = map(string)
302+
default = {}
303+
}
304+
305+
variable "identity_type" {
306+
description = "Type of managed identity to set"
307+
type = string
308+
default = null
309+
}
310+
311+
variable "user_assigned_identity_ids" {
312+
description = "List of user-assigned managed identity IDs"
313+
type = list(string)
314+
default = []
315+
}
316+
317+
variable "entra_authentication" {
318+
description = "Azure Entra authentication configuration block for Azure MySQL Flexible Server"
319+
type = object({
320+
user_assigned_identity_id = optional(string, null)
321+
login = optional(string, null)
322+
object_id = optional(string, null)
323+
})
324+
default = {}
325+
}

0 commit comments

Comments
 (0)