-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
99 lines (82 loc) · 3.4 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
resource "azurerm_postgresql_server" "sql_server" {
name = var.sql_name
location = var.resource_group_location
resource_group_name = var.resource_group_name
sku_name = var.sku_name
storage_mb = var.storage_mb
backup_retention_days = var.backup_retention_days
geo_redundant_backup_enabled = var.geo_redundant_backup_enabled
auto_grow_enabled = var.auto_grow_enabled
administrator_login = var.admin_login
administrator_login_password = var.administrator_login_password
version = var.server_version
ssl_enforcement_enabled = var.ssl_enforcement_enabled
public_network_access_enabled = var.public_network_access_enabled
}
resource "azurerm_postgresql_virtual_network_rule" "postgres_vnet_rule" {
name = var.sql_name
resource_group_name = var.resource_group_name
server_name = azurerm_postgresql_server.sql_server.name
subnet_id = var.subnet_id
ignore_missing_vnet_service_endpoint = true
depends_on = [
azurerm_postgresql_server.sql_server
]
}
resource "azurerm_postgresql_database" "sql_db" {
name = var.sql_db_name
resource_group_name = var.resource_group_name
server_name = azurerm_postgresql_server.sql_server.name
charset = var.db_charset
collation = var.db_collation
depends_on = [
azurerm_postgresql_server.sql_server
]
}
resource "azurerm_private_endpoint" "private_endpoint" {
name = var.private_endpoint_name
location = var.resource_group_location
resource_group_name = var.resource_group_name
subnet_id = var.subnet_id
private_service_connection {
name = var.private_endpoint_name
private_connection_resource_id = azurerm_postgresql_server.sql_server.id
subresource_names = [ "postgresqlServer" ]
is_manual_connection = false
}
ip_configuration {
name = var.private_endpoint_name
private_ip_address = var.postres_private_ip
subresource_name = "postgresqlServer"
member_name = "postgresqlServer"
}
depends_on = [
azurerm_postgresql_server.sql_server
]
}
resource "azurerm_private_dns_zone" "private_dns" {
name = "${var.postgres_dns_name}.postgres.database.azure.com"
resource_group_name = var.resource_group_name
depends_on = [
azurerm_private_endpoint.private_endpoint
]
}
resource "azurerm_private_dns_zone_virtual_network_link" "network_link" {
name = "${var.postgres_dns_name}"
resource_group_name = var.resource_group_name
private_dns_zone_name = azurerm_private_dns_zone.private_dns.name
virtual_network_id = var.vnet_id
depends_on = [
azurerm_private_dns_zone.private_dns
]
}
resource "azurerm_private_dns_a_record" "dns_record" {
name = "db"
zone_name = azurerm_private_dns_zone.private_dns.name
resource_group_name = var.resource_group_name
ttl = var.time_to_live
records = [var.postres_private_ip]
depends_on = [
azurerm_private_dns_zone.private_dns
]
}