-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
226 lines (177 loc) · 5.08 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
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
226
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.39.0"
}
azuread = {
source = "hashicorp/azuread"
version = "1.3.0"
}
}
}
provider "azurerm" {
subscription_id = var.subscription_id
tenant_id = var.tenant_id
client_id = var.client_id
client_secret = var.client_secret
features {}
}
locals {
env = var.env[terraform.workspace]
location = var.location[terraform.workspace]
env_tags = {
env = local.env
}
aiof_tags = {
env = local.env
app = var.app
}
}
resource "azurerm_resource_group" "aiof_rg" {
name = "aiof-${local.env}"
location = local.location
tags = local.aiof_tags
}
data "azurerm_client_config" "current_rg" {}
resource "azurerm_key_vault" "aiof_kv" {
name = "aiof-${local.env}-kv"
location = azurerm_resource_group.aiof_rg.location
resource_group_name = azurerm_resource_group.aiof_rg.name
enabled_for_disk_encryption = false
tenant_id = data.azurerm_client_config.current_rg.tenant_id
soft_delete_enabled = false
purge_protection_enabled = false
sku_name = "standard"
access_policy {
tenant_id = data.azurerm_client_config.current_rg.tenant_id
object_id = data.azurerm_client_config.current_rg.object_id
key_permissions = [
"get",
]
secret_permissions = [
"get",
"set",
"delete",
]
storage_permissions = [
"get",
]
}
access_policy {
tenant_id = data.azurerm_client_config.current_rg.tenant_id
object_id = data.azuread_user.gkamacharov.object_id
key_permissions = [
"list",
"get",
"create",
"delete",
]
secret_permissions = [
"list",
"get",
"set",
"delete",
]
storage_permissions = [
"set",
]
}
network_acls {
default_action = "Allow"
bypass = "AzureServices"
}
tags = local.env_tags
}
resource "azurerm_key_vault_secret" "kv_jwt_private_key" {
name = var.kv_jwt_private_key
value = var.appsettings_auth_jwt_private_key_value
key_vault_id = azurerm_key_vault.aiof_kv.id
tags = local.env_tags
}
resource "azurerm_key_vault_secret" "kv_jwt_public_key" {
name = var.kv_jwt_public_key
value = var.appsettings_auth_jwt_public_key_value
key_vault_id = azurerm_key_vault.aiof_kv.id
tags = local.env_tags
}
resource "azurerm_application_insights" "heimdall" {
name = "heimdall-${local.env}"
location = azurerm_resource_group.aiof_rg.location
resource_group_name = azurerm_resource_group.aiof_rg.name
application_type = "web"
}
resource "azurerm_app_service_plan" "aiof_app_service_plan" {
name = "aiof-service-plan-${local.env}"
location = azurerm_resource_group.aiof_rg.location
resource_group_name = azurerm_resource_group.aiof_rg.name
kind = "Linux"
reserved = true
sku {
tier = "Basic"
size = "B1"
}
tags = local.env_tags
}
/*
Database
*/
module "database" {
source = "./modules/database"
location = local.location
env = local.env
env_tags = local.env_tags
rg = {
location = azurerm_resource_group.aiof_rg.location
name = azurerm_resource_group.aiof_rg.name
}
db_admin_username = var.db_admin_username
db_admin_password = var.db_admin_password
db_admin_start_ip = var.db_admin_start_ip
}
/*
Messaging
*/
module "messaging" {
source = "./modules/messaging"
location = local.location
env = local.env
app_service_plan_id = azurerm_app_service_plan.aiof_app_service_plan.id
}
/*
Eventing
*/
module "eventing" {
source = "./modules/eventing"
location = local.location
env = local.env
app_service_plan_id = azurerm_app_service_plan.aiof_app_service_plan.id
application_insights_instrumentation_key = azurerm_application_insights.heimdall.instrumentation_key
application_insights_connection_string = azurerm_application_insights.heimdall.connection_string
}
/*
App
*/
module "app" {
source = "./modules/app"
location = local.location
env = local.env
env_tags = local.env_tags
rg = {
location = azurerm_resource_group.aiof_rg.location
name = azurerm_resource_group.aiof_rg.name
}
app_service_plan_id = azurerm_app_service_plan.aiof_app_service_plan.id
appsettings_auth_jwt_private_key_value = var.appsettings_auth_jwt_private_key_value
appsettings_auth_jwt_public_key_value = var.appsettings_auth_jwt_public_key_value
application_insights_instrumentation_key = azurerm_application_insights.heimdall.instrumentation_key
database_connection_string = module.database.database_connection_string
emitter_hostname = module.eventing.emitter_hostname
emitter_function_key = module.eventing.emitter_function_key
depends_on = [
azurerm_application_insights.heimdall,
module.database,
module.messaging,
module.eventing
]
}