-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapgw.tf
More file actions
158 lines (136 loc) · 4.85 KB
/
apgw.tf
File metadata and controls
158 lines (136 loc) · 4.85 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
#Reference : https://faun.pub/build-an-azure-application-gateway-with-terraform-8264fbd5fa42
#Updated at 2022.02.05
#appgw with key vault
############### 진행중 ########################
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_virtual_network" "example" {
name = "example-network"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
address_space = ["10.254.0.0/16"]
}
resource "azurerm_subnet" "frontend" {
name = "frontend"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.254.0.0/24"]
}
resource "azurerm_subnet" "backend" {
name = "backend"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.254.2.0/24"]
}
resource "azurerm_public_ip" "example" {
name = "example-pip"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
allocation_method = "Dynamic"
}
# -
# - Application Gateway (L7 load balancer)
# -
resource "azurerm_application_gateway" "agw" {
depends_on = [azurerm_key_vault_certificate.mysite1, time_sleep.wait_60_seconds]
name = "${local.prefix}-hub-agw1"
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
enable_http2 = true
zones = local.zones
tags = data.azurerm_resource_group.rg.tags
sku {
name = local.sku_name
tier = local.sku_tier
}
autoscale_configuration {
min_capacity = local.capacity.min
max_capacity = local.capacity.max
}
identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.agw.id]
}
gateway_ip_configuration {
name = "${local.prefix}-hub-agw1-ip-configuration"
subnet_id = local.subnet_id
}
frontend_ip_configuration {
name = "${local.frontend_ip_configuration_name}-public"
public_ip_address_id = azurerm_public_ip.agw.id
}
frontend_port {
name = "${local.frontend_port_name}-80"
port = 80
}
frontend_port {
name = "${local.frontend_port_name}-443"
port = 443
}
backend_address_pool {
name = local.backend_address_pool.name
fqdns = local.backend_address_pool.fqdns
}
ssl_certificate {
name = azurerm_key_vault_certificate.mysite1.name
key_vault_secret_id = azurerm_key_vault_certificate.mysite1.secret_id
}
backend_http_settings {
name = local.http_setting_name
cookie_based_affinity = "Disabled"
port = 443
protocol = "Https"
host_name = local.backend_address_pool.fqdns[0]
request_timeout = 1
}
http_listener {
name = "${local.listener_name}-http"
frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}-public"
frontend_port_name = "${local.frontend_port_name}-80"
protocol = "Http"
}
http_listener {
name = "${local.listener_name}-https"
frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}-public"
frontend_port_name = "${local.frontend_port_name}-443"
protocol = "Https"
ssl_certificate_name = azurerm_key_vault_certificate.mysite1.name
}
request_routing_rule {
name = "${local.request_routing_rule_name}-https"
rule_type = "Basic"
http_listener_name = "${local.listener_name}-https"
backend_address_pool_name = local.backend_address_pool.name
backend_http_settings_name = local.http_setting_name
}
redirect_configuration {
name = local.redirect_configuration_name
redirect_type = "Permanent"
include_path = true
include_query_string = true
target_listener_name = "${local.listener_name}-https"
}
request_routing_rule {
name = "${local.request_routing_rule_name}-http"
rule_type = "Basic"
http_listener_name = "${local.listener_name}-http"
redirect_configuration_name = local.redirect_configuration_name
}
// Ignore most changes as they will be managed manually
lifecycle {
ignore_changes = [
backend_address_pool,
backend_http_settings,
frontend_port,
http_listener,
probe,
request_routing_rule,
url_path_map,
ssl_certificate,
redirect_configuration,
autoscale_configuration
]
}
}