Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add postgresql to database module #10

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"azure",
"mysql-flexible-server",
"mysql-flexible-database",
"mysql-flexible-server-firewall-rule"
"mysql-flexible-configuration",
"mysql-flexible-server-firewall-rule",
"postgresql-flexible-server",
"postgresql-flexible-server-database",
"postgresql-flexible-server-configuration",
"postgresql-flexible-server-firewall-rule"
]
}
}
27 changes: 27 additions & 0 deletions examples/apply_main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,31 @@ module "database" {
end_ip_address = cidrhost("0.0.0.0/32", -1)
}
}
postgresql_flexible_server = {
postgresql-mms = {
location = "westeurope"
resource_group_name = "rg-mms-github"
administrator_login = "postgresql_root"
administrator_password = random_password.password["postgresql_root"].result
sku_name = "GP_Standard_D2ds_v5"
}
}
postgresql_flexible_server_configuration = {
backslash_quote = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
value = "on"
}
}
postgresql_flexible_server_database = {
application = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
}
}
postgresql_flexible_server_firewall_rule = {
AzureServices = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
start_ip_address = cidrhost("0.0.0.0/32", 0)
end_ip_address = cidrhost("0.0.0.0/32", -1)
}
}
}
42 changes: 41 additions & 1 deletion examples/full_main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "random_password" "password" {
for_each = toset(["mysql_root"])
for_each = toset(["mysql_root", "postgresql_root"])

length = 16
special = false
Expand Down Expand Up @@ -51,4 +51,44 @@ module "database" {
end_ip_address = cidrhost("0.0.0.0/32", -1)
}
}

postgresql_flexible_server = {
postgresql-mms = {
location = "westeurope"
resource_group_name = "rg-mms-github"
administrator_login = "postgresql_root"
administrator_password = random_password.password["postgresql_root"].result
sku_name = "GP_Standard_D2ds_v5"
storage_mb = 32768
version = "16"
zone = "1"
high_availability = {
mode = "ZoneRedundant"
standby_availability_zone = 2
}
tags = {
project = "mms-github"
environment = terraform.workspace
managed-by = "terraform"
}
}
}
postgresql_flexible_server_configuration = {
backslash_quote = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
value = "on"
}
}
postgresql_flexible_server_database = {
application = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
}
}
postgresql_flexible_server_firewall_rule = {
AzureServices = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
start_ip_address = cidrhost("0.0.0.0/32", 0)
end_ip_address = cidrhost("0.0.0.0/32", -1)
}
}
}
29 changes: 28 additions & 1 deletion examples/min_main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "random_password" "password" {
for_each = toset(["mysql_root"])
for_each = toset(["mysql_root", "postgresql_root"])

length = 16
special = false
Expand Down Expand Up @@ -37,4 +37,31 @@ module "database" {
end_ip_address = cidrhost("0.0.0.0/32", -1)
}
}
postgresql_flexible_server = {
postgresql-mms = {
location = "westeurope"
resource_group_name = "rg-mms-github"
administrator_login = "postgresql_root"
administrator_password = random_password.password["postgresql_root"].result
sku_name = "GP_Standard_D2ds_v5"
}
}
postgresql_flexible_server_configuration = {
backslash_quote = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
value = "on"
}
}
postgresql_flexible_server_database = {
application = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
}
}
postgresql_flexible_server_firewall_rule = {
AzureServices = {
server_id = module.database.postgresql_flexible_server["postgresql-mms"].id
start_ip_address = cidrhost("0.0.0.0/32", 0)
end_ip_address = cidrhost("0.0.0.0/32", -1)
}
}
}
100 changes: 100 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,103 @@ resource "azurerm_mysql_flexible_server_firewall_rule" "mysql_flexible_server_fi
start_ip_address = local.mysql_flexible_server_firewall_rule[each.key].start_ip_address
end_ip_address = local.mysql_flexible_server_firewall_rule[each.key].end_ip_address
}

resource "azurerm_postgresql_flexible_server" "postgresql_flexible_server" {
for_each = var.postgresql_flexible_server

name = local.postgresql_flexible_server[each.key].name == "" ? each.key : local.postgresql_flexible_server[each.key].name
resource_group_name = local.postgresql_flexible_server[each.key].resource_group_name
location = local.postgresql_flexible_server[each.key].location
administrator_login = local.postgresql_flexible_server[each.key].administrator_login
administrator_password = local.postgresql_flexible_server[each.key].administrator_password
backup_retention_days = local.postgresql_flexible_server[each.key].backup_retention_days
create_mode = local.postgresql_flexible_server[each.key].create_mode
delegated_subnet_id = local.postgresql_flexible_server[each.key].delegated_subnet_id
geo_redundant_backup_enabled = local.postgresql_flexible_server[each.key].geo_redundant_backup_enabled
point_in_time_restore_time_in_utc = local.postgresql_flexible_server[each.key].point_in_time_restore_time_in_utc
private_dns_zone_id = local.postgresql_flexible_server[each.key].private_dns_zone_id
replication_role = local.postgresql_flexible_server[each.key].replication_role
sku_name = local.postgresql_flexible_server[each.key].sku_name
source_server_id = local.postgresql_flexible_server[each.key].source_server_id
auto_grow_enabled = local.postgresql_flexible_server[each.key].auto_grow_enabled
storage_mb = local.postgresql_flexible_server[each.key].storage_mb
version = local.postgresql_flexible_server[each.key].version
zone = local.postgresql_flexible_server[each.key].zone


dynamic "authentication" {
for_each = length(compact(values(local.postgresql_flexible_server[each.key].authentication))) > 0 ? [0] : []

content {
active_directory_auth_enabled = local.postgresql_flexible_server[each.key].authentication_key.active_directory_auth_enabled
password_auth_enabled = local.postgresql_flexible_server[each.key].authentication_key.password_auth_enabled
tenant_id = local.postgresql_flexible_server[each.key].authentication_key.tenant_id
}
}

dynamic "customer_managed_key" {
for_each = length(compact(values(local.postgresql_flexible_server[each.key].customer_managed_key))) > 0 ? [0] : []

content {
key_vault_key_id = local.postgresql_flexible_server[each.key].customer_managed_key.key_vault_key_id
primary_user_assigned_identity_id = local.postgresql_flexible_server[each.key].customer_managed_key.primary_user_assigned_identity_id
geo_backup_key_vault_key_id = local.postgresql_flexible_server[each.key].customer_managed_key.geo_backup_key_vault_key_id
geo_backup_user_assigned_identity_id = local.postgresql_flexible_server[each.key].customer_managed_key.geo_backup_user_assigned_identity_id
}
}

dynamic "high_availability" {
for_each = length(compact(values(local.postgresql_flexible_server[each.key].high_availability))) > 0 ? [0] : []

content {
mode = local.postgresql_flexible_server[each.key].high_availability.mode
standby_availability_zone = local.postgresql_flexible_server[each.key].high_availability.standby_availability_zone
}
}

dynamic "identity" {
for_each = local.postgresql_flexible_server[each.key].identity == {} ? [] : [0]

content {
type = local.postgresql_flexible_server[each.key].identity.type
identity_ids = local.postgresql_flexible_server[each.key].identity.identity_ids
}
}

dynamic "maintenance_window" {
for_each = length(compact(values(local.postgresql_flexible_server[each.key].maintenance_window))) > 0 ? [0] : []

content {
day_of_week = local.postgresql_flexible_server[each.key].maintenance_window.day_of_week
start_hour = local.postgresql_flexible_server[each.key].maintenance_window.start_hour
start_minute = local.postgresql_flexible_server[each.key].maintenance_window.start_minute
}
}
tags = local.postgresql_flexible_server[each.key].tags
}

resource "azurerm_postgresql_flexible_server_configuration" "postgresql_flexible_server_configuration" {
for_each = var.postgresql_flexible_server_configuration

name = local.postgresql_flexible_server_configuration[each.key].name == "" ? each.key : local.postgresql_flexible_server_configuration[each.key].name
server_id = local.postgresql_flexible_server_configuration[each.key].server_id
value = local.postgresql_flexible_server_configuration[each.key].value
}

resource "azurerm_postgresql_flexible_server_database" "postgresql_flexible_server_database" {
for_each = var.postgresql_flexible_server_database

name = local.postgresql_flexible_server_database[each.key].name == "" ? each.key : local.postgresql_flexible_server_database[each.key].name
server_id = local.postgresql_flexible_server_database[each.key].server_id
charset = local.postgresql_flexible_server_database[each.key].charset
collation = local.postgresql_flexible_server_database[each.key].collation
}

resource "azurerm_postgresql_flexible_server_firewall_rule" "postgresql_flexible_server_firewall_rule" {
for_each = var.postgresql_flexible_server_firewall_rule

name = local.postgresql_flexible_server_firewall_rule[each.key].name == "" ? each.key : local.postgresql_flexible_server_firewall_rule[each.key].name
server_id = local.postgresql_flexible_server_firewall_rule[each.key].server_id
start_ip_address = local.postgresql_flexible_server_firewall_rule[each.key].start_ip_address
end_ip_address = local.postgresql_flexible_server_firewall_rule[each.key].end_ip_address
}
60 changes: 60 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,50 @@ output "mysql_flexible_server_firewall_rule" {
}
}

output "postgresql_flexible_server" {
description = "Outputs all attributes of resource_type."
value = {
for postgresql_flexible_server in keys(azurerm_postgresql_flexible_server.postgresql_flexible_server) :
postgresql_flexible_server => {
for key, value in azurerm_postgresql_flexible_server.postgresql_flexible_server[postgresql_flexible_server] :
key => value
}
}
}

output "postgresql_flexible_server_configuration" {
description = "Outputs all attributes of resource_type."
value = {
for postgresql_flexible_server_configuration in keys(azurerm_postgresql_flexible_server_configuration.postgresql_flexible_server_configuration) :
postgresql_flexible_server_configuration => {
for key, value in azurerm_postgresql_flexible_server_configuration.postgresql_flexible_server_configuration[postgresql_flexible_server_configuration] :
key => value
}
}
}

output "postgresql_flexible_server_database" {
description = "Outputs all attributes of resource_type."
value = {
for postgresql_flexible_server_database in keys(azurerm_postgresql_flexible_server_database.postgresql_flexible_server_database) :
postgresql_flexible_server_database => {
for key, value in azurerm_postgresql_flexible_server_database.postgresql_flexible_server_database[postgresql_flexible_server_database] :
key => value
}
}
}

output "postgresql_flexible_server_firewall_rule" {
description = "Outputs all attributes of resource_type."
value = {
for postgresql_flexible_server_firewall_rule in keys(azurerm_postgresql_flexible_server_firewall_rule.postgresql_flexible_server_firewall_rule) :
postgresql_flexible_server_firewall_rule => {
for key, value in azurerm_postgresql_flexible_server_firewall_rule.postgresql_flexible_server_firewall_rule[postgresql_flexible_server_firewall_rule] :
key => value
}
}
}

output "variables" {
description = "Displays all configurable variables passed by the module. __default__ = predefined values per module. __merged__ = result of merging the default values and custom values passed to the module"
value = {
Expand All @@ -66,6 +110,22 @@ output "variables" {
for key in keys(var.mysql_flexible_server_firewall_rule) :
key => local.mysql_flexible_server_firewall_rule[key]
}
postgresql_flexible_server = {
for key in keys(var.postgresql_flexible_server) :
key => local.postgresql_flexible_server[key]
}
postgresql_flexible_server_configuration = {
for key in keys(var.postgresql_flexible_server_configuration) :
key => local.postgresql_flexible_server_configuration[key]
}
postgresql_flexible_server_database = {
for key in keys(var.postgresql_flexible_server_database) :
key => local.postgresql_flexible_server_database[key]
}
postgresql_flexible_server_firewall_rule = {
for key in keys(var.postgresql_flexible_server_firewall_rule) :
key => local.postgresql_flexible_server_firewall_rule[key]
}
}
}
}
Loading
Loading