-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
225 lines (168 loc) · 6.08 KB
/
main.tf
File metadata and controls
225 lines (168 loc) · 6.08 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#--------------------------------------------------------------
# Azure Infrastructure Resources
#
# Purpose: Core infrastructure for bakery order system
#
#--------------------------------------------------------------
resource "azurerm_resource_group" "main" {
name = "${var.project_name}-rg-${var.environment}"
location = var.location
}
resource "azurerm_virtual_network" "main" {
name = "${var.project_name}-vnet-${var.environment}"
address_space = var.vnet_address_space
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
}
resource "azurerm_subnet" "app_intergration" {
name = "app-intergration-subnet"
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = var.app_subnet_prefix
delegation {
name = "app-serevice-intergraion"
service_delegation {
name = "Microsoft.Web/serverFarms"
actions = [
"Microsoft.Network/virtualNetworks/subnets/action"
]
}
}
}
resource "azurerm_subnet" "private_endpoints" {
name = "private-endpoints-subnet"
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = var.pe_subnet_prefix
}
resource "azurerm_subnet" "mysql" {
name = "mysql-subnet"
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = var.mysql_subnet_prefix
delegation {
name = "mysql-delegation"
service_delegation {
name = "Microsoft.DBforMySQL/flexibleServers"
actions = [
"Microsoft.Network/virtualNetworks/subnets/join/action"
]
}
}
}
resource "azurerm_mysql_flexible_server" "main" {
name = "${var.project_name}-mysql-${var.environment}"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
administrator_login = var.my_sql_admin_username
administrator_password = var.my_sql_admin_password
backup_retention_days = 7
sku_name = "B_Standard_B1ms"
version = "8.0.21"
storage {
size_gb = 20
}
geo_redundant_backup_enabled = false
delegated_subnet_id = azurerm_subnet.mysql.id
private_dns_zone_id = azurerm_private_dns_zone.mysql.id
depends_on = [azurerm_private_dns_zone_virtual_network_link.mysql]
}
resource "azurerm_private_dns_zone" "mysql" {
name = "privatelink.mysql.database.azure.com"
resource_group_name = azurerm_resource_group.main.name
}
resource "azurerm_private_dns_zone_virtual_network_link" "mysql" {
name = "my-sql-dns-link"
resource_group_name = azurerm_resource_group.main.name
private_dns_zone_name = azurerm_private_dns_zone.mysql.name
virtual_network_id = azurerm_virtual_network.main.id
}
resource "azurerm_storage_account" "main" {
name = var.storage_account_name
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
account_tier = "Standard"
account_replication_type = "LRS"
# Security settings
min_tls_version = "TLS1_2"
allow_nested_items_to_be_public = false
public_network_access_enabled = false
# Enable encryption
blob_properties {
delete_retention_policy {
days = 7
}
}
}
# Blob Container
resource "azurerm_storage_container" "main" {
name = var.storage_container_name
storage_account_id = azurerm_storage_account.main.id
container_access_type = "private"
}
# Private DNS Zone for Blob Storage
resource "azurerm_private_dns_zone" "blob" {
name = "privatelink.blob.core.windows.net"
resource_group_name = azurerm_resource_group.main.name
}
# Link DNS Zone to VNET
resource "azurerm_private_dns_zone_virtual_network_link" "blob" {
name = "blob-dns-link"
resource_group_name = azurerm_resource_group.main.name
private_dns_zone_name = azurerm_private_dns_zone.blob.name
virtual_network_id = azurerm_virtual_network.main.id
}
# Private Endpoint for Blob Storage
resource "azurerm_private_endpoint" "blob" {
name = "${var.project_name}-blob-pe-${var.environment}"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
subnet_id = azurerm_subnet.private_endpoints.id
private_service_connection {
name = "blob-private-connection"
private_connection_resource_id = azurerm_storage_account.main.id
is_manual_connection = false
subresource_names = ["blob"]
}
private_dns_zone_group {
name = "blob-dns-zone-group"
private_dns_zone_ids = [azurerm_private_dns_zone.blob.id]
}
}
# App Service Plan
resource "azurerm_service_plan" "main" {
name = "${var.project_name}-plan-${var.environment}"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
os_type = "Linux"
sku_name = var.app_service_plan_sku
}
# App Service
resource "azurerm_linux_web_app" "main" {
name = "${var.app_name}-${var.environment}"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
service_plan_id = azurerm_service_plan.main.id
# VNET Integration
virtual_network_subnet_id = azurerm_subnet.app_intergration.id
site_config {
# Security settings
minimum_tls_version = "1.2"
# Always on (keeps app warm)
always_on = true
vnet_route_all_enabled = true
application_stack {
node_version = "20-lts"
}
}
# Force HTTPS
https_only = true
# App Settings (environment variables)
app_settings = {
"WEBSITE_DNS_SERVER" = "168.63.129.16"
}
# Identity for accessing other Azure resources
identity {
type = "SystemAssigned"
}
}