generated from UKHO/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
143 lines (123 loc) · 4.34 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
resource "azurerm_user_assigned_identity" "tf" {
provider = azurerm.sub
name = "appservice-identity"
location = var.location
resource_group_name = var.resource_group_name
}
resource "azurerm_app_service_plan" "app_service_plan" {
provider = azurerm.sub
name = "${var.name}-asp"
location = var.location
resource_group_name = var.resource_group_name
kind = "Linux"
reserved = true
sku {
tier = "PremiumV3"
size = "P1v3"
}
tags = var.tags
}
resource "azurerm_app_service" "webapp_service" {
provider = azurerm.sub
name = var.name
location = var.location
resource_group_name = var.resource_group_name
app_service_plan_id = azurerm_app_service_plan.app_service_plan.id
tags = var.tags
https_only = true
site_config {
linux_fx_version = "DOTNETCORE|6.0"
always_on = true
http2_enabled = true
ftps_state = "Disabled"
ip_restriction = var.ip_restrictions
}
depends_on = [
azurerm_app_service_plan.app_service_plan,
azurerm_user_assigned_identity.tf
]
app_settings = var.app_settings
identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.tf.id]
}
}
resource "azurerm_app_service_slot" "webapp_service_slot_inactive" {
provider = azurerm.sub
name = "Inactive"
location = var.location
app_service_name = azurerm_app_service.webapp_service.name
resource_group_name = var.resource_group_name
app_service_plan_id = azurerm_app_service_plan.app_service_plan.id
tags = var.tags
https_only = true
site_config {
linux_fx_version = "DOTNETCORE|6.0"
always_on = true
http2_enabled = true
ftps_state = "Disabled"
ip_restriction = var.ip_restrictions
}
depends_on = [
azurerm_app_service_plan.app_service_plan,
azurerm_user_assigned_identity.tf
]
app_settings = var.app_settings
identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.tf.id]
}
}
resource "azurerm_app_service_virtual_network_swift_connection" "webapp_vnet_integration" {
provider = azurerm.sub
app_service_id = azurerm_app_service.webapp_service.id
subnet_id = var.subnet_id
}
resource "azurerm_app_service_slot_virtual_network_swift_connection" "webapp_inactive_slot_vnet_integration" {
provider = azurerm.sub
slot_name = azurerm_app_service_slot.webapp_service_slot_inactive.name
app_service_id = azurerm_app_service.webapp_service.id
subnet_id = var.subnet_id
}
// First Read the External Key Vault
data "azurerm_key_vault" "certskv" {
provider = azurerm.ssl
name = var.certificate_key_vault_name
resource_group_name = var.certificate_key_vault_rg
}
// Now Read the Certificate
data "azurerm_key_vault_certificate" "kvcert" {
provider = azurerm.ssl
name = var.certificate_name
key_vault_id = data.azurerm_key_vault.certskv.id
}
//Get Certificate from External KeyVault
resource "azurerm_app_service_certificate" "cert" {
provider = azurerm.sub
name = var.certificate_name
resource_group_name = var.resource_group_name
location = var.location
key_vault_secret_id = data.azurerm_key_vault_certificate.kvcert.id
}
resource "azurerm_app_service_custom_hostname_binding" "domain" {
provider = azurerm.sub
depends_on = [ azurerm_app_service_certificate.cert ]
hostname = var.custom_domain
app_service_name = azurerm_app_service.webapp_service.name
resource_group_name = var.resource_group_name
# Ignore ssl_state and thumbprint as they are managed using
# azurerm_app_service_certificate_binding.example
lifecycle {
ignore_changes = [ssl_state, thumbprint]
}
}
resource "azurerm_app_service_managed_certificate" "tf" {
provider = azurerm.sub
custom_hostname_binding_id = azurerm_app_service_custom_hostname_binding.domain.id
}
resource "azurerm_app_service_certificate_binding" "example" {
provider = azurerm.sub
hostname_binding_id = azurerm_app_service_custom_hostname_binding.domain.id
certificate_id = azurerm_app_service_managed_certificate.tf.id
ssl_state = "SniEnabled"
}