-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
150 lines (130 loc) · 5.36 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
## Azure resource provider ##
provider "azurerm" {
version = "~>2.0"
features {}
}
## Azure terraform backend
terraform {
backend "azurerm" {
resource_group_name = "aks-csye7125-rg"
storage_account_name = "tfstatesecsyeproject"
container_name = "tfstates"
key = "dbService/tfstate"
}
}
resource "azurerm_virtual_network" "azure_mysql_vnet" {
name = "azure_mysql_vnet"
address_space = ["172.0.0.0/16"]
location = var.location
resource_group_name = var.resource_group_name
}
resource "azurerm_subnet" "azure_mysql_subnet" {
name = "azure_mysql_subnet"
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.azure_mysql_vnet.name
address_prefixes = ["172.0.0.0/24"]
service_endpoints = ["Microsoft.Sql"]
delegation {
name = "mydelegation"
service_delegation {
name = "Microsoft.DBforMySQL/flexibleServers"
actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"]
}
}
}
resource "azurerm_mysql_virtual_network_rule" "azure_mysql_vnetrule1" {
name = var.networkrule_name
resource_group_name = var.resource_group_name
server_name = azurerm_mysql_server.webapp_db.name
subnet_id = var.subnet_id
}
resource "azurerm_mysql_firewall_rule" "demo-allow-demo-instance" {
name = var.webapp_db
resource_group_name = var.resource_group_name
server_name = azurerm_mysql_server.webapp_db.name
start_ip_address = var.private_start_ip_address
end_ip_address = var.private_end_ip_address
##https://docs.microsoft.com/en-us/azure/azure-sql/database/network-access-controls-overview
}
/*
# resource "azurerm_mysql_virtual_network_rule" "azure_mysql_vnet_rule_poller" {
# name = "azure_mysql_vnet_rule_poller"
# resource_group_name = var.resource_group_name
# server_name = azurerm_mysql_server.poller_db.name
# subnet_id = azurerm_subnet.azure_mysql_subnet.id
# }
# resource "azurerm_mysql_virtual_network_rule" "azure_mysql_vnet_rule_notifier" {
# name = "azure_mysql_vnet_rule_notifier"
# resource_group_name = var.resource_group_name
# server_name = azurerm_mysql_server.notifier_db.name
# subnet_id = azurerm_subnet.azure_mysql_subnet.id
# }
*/
resource "azurerm_mysql_server" "webapp_db" {
name = var.webapp_db
location = var.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
administrator_login = var.admin_username
administrator_login_password = var.admin_password
version = var.db_version
ssl_enforcement_enabled = var.ssl_enforcement
}
resource "azurerm_mysql_database" "webappdb" {
name = "webappdb"
resource_group_name = var.resource_group_name
server_name = azurerm_mysql_server.webapp_db.name
charset = "utf8"
collation = "utf8_unicode_ci"
}
# resource "azurerm_virtual_network_peering" "aks-to-db-peering" {
# name = "aks-to-db-peering"
# resource_group_name = var.resource_group_name
# virtual_network_name = azurerm_virtual_network.azure_mysql_vnet.name
# remote_virtual_network_id = azurerm_virtual_network.example-2.id
# allow_virtual_network_access = true
# allow_forwarded_traffic = false
# allow_gateway_transit = false
# }
# resource "azurerm_virtual_network_peering" "db-to-aks-peering" {
# name = "db-to-aks-peering"
# resource_group_name = var.resource_group_name
# virtual_network_name = azurerm_virtual_network.azure_mysql_vnet.name
# remote_virtual_network_id = azurerm_virtual_network.example-2.id
# allow_virtual_network_access = true
# allow_forwarded_traffic = false
# allow_gateway_transit = false
# }
/*
resource "azurerm_mysql_server" "poller_db" {
name = var.poller_db
location = var.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
administrator_login = "polleruser"
administrator_login_password = "Pass1234"
databases_names = ["pollerdb"]
version = var.db_version
ssl_enforcement_enabled = var.ssl_enforcement
}
resource "azurerm_mysql_server" "notifier_db" {
name = var.notifier_db
location = var.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
administrator_login = "notifieruser"
administrator_login_password = "Pass1234"
databases_names = ["notifierdb"]
version = var.db_version
ssl_enforcement_enabled = var.ssl_enforcement
}
*/