-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
155 lines (132 loc) · 4.43 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
locals {
service_name = "${var.base_name}${var.location}"
}
# API MANAGEMENT
resource "azurerm_api_management" "apim_service" {
name = local.service_name
location = var.location
resource_group_name = var.resource_group_name
publisher_name = "Publisher"
publisher_email = "publisher@example.com"
sku_name = "Consumption_0"
identity {
type = "SystemAssigned"
}
}
resource "azurerm_api_management_api" "inventory" {
name = "Inventory"
resource_group_name = var.resource_group_name
api_management_name = azurerm_api_management.apim_service.name
revision = "1"
display_name = "Inventory"
path = "inventory"
protocols = ["https"]
service_url = "https://${azurerm_windows_function_app.fxn_app.default_hostname}"
subscription_required = false
}
resource "azurerm_api_management_api_operation" "get_product_by_id" {
operation_id = "GetProductById"
api_name = azurerm_api_management_api.inventory.name
api_management_name = azurerm_api_management.apim_service.name
resource_group_name = var.resource_group_name
display_name = "GetProductById"
method = "GET"
url_template = "/api/product/{id}"
description = "Retrieves Product by Id"
response {
status_code = 200
}
template_parameter {
name = "id"
required = true
type = "string"
}
}
resource "azurerm_api_management_api_operation" "get_products" {
operation_id = "GetProducts"
api_name = azurerm_api_management_api.inventory.name
api_management_name = azurerm_api_management.apim_service.name
resource_group_name = var.resource_group_name
display_name = "GetProducts"
method = "GET"
url_template = "/api/products"
description = "Retrieves all Products"
response {
status_code = 200
}
}
# Microsoft Entra ID
resource "azuread_application" "entra_application" {
display_name = local.service_name
web {
redirect_uris = ["https://${local.service_name}.azurewebsites.net/.auth/login/aad/callback"]
implicit_grant {
access_token_issuance_enabled = true
}
}
}
# AZURE FUNCTION
resource "azurerm_application_insights" "fxn_app_insights" {
name = local.service_name
location = var.location
resource_group_name = var.resource_group_name
application_type = "web"
}
resource "azurerm_storage_account" "fxn_storage" {
name = local.service_name
resource_group_name = var.resource_group_name
location = var.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_service_plan" "fxn_ase" {
name = local.service_name
location = var.location
resource_group_name = var.resource_group_name
os_type = "Windows"
sku_name = var.app_service_sku
}
resource "azurerm_windows_function_app" "fxn_app" {
name = local.service_name
location = var.location
resource_group_name = var.resource_group_name
service_plan_id = azurerm_service_plan.fxn_ase.id
storage_account_name = azurerm_storage_account.fxn_storage.name
storage_account_access_key = azurerm_storage_account.fxn_storage.primary_access_key
site_config {
application_stack {
dotnet_version = "v8.0"
use_dotnet_isolated_runtime = true
}
}
identity {
type = "SystemAssigned"
}
auth_settings_v2 {
auth_enabled = true
login {}
active_directory_v2 {
client_id = azuread_application.entra_application.client_id
tenant_auth_endpoint = "https://login.microsoftonline.com/${var.tenant_id}/v2.0/"
allowed_identities = [azurerm_api_management.apim_service.identity[0].principal_id]
}
}
lifecycle {
ignore_changes = [
app_settings,
ftp_publish_basic_authentication_enabled,
webdeploy_publish_basic_authentication_enabled
]
}
}
resource "azurerm_monitor_diagnostic_setting" "fxn_app_diagnostic_setting" {
name = "fxnappdiagnosticsetting"
target_resource_id = azurerm_windows_function_app.fxn_app.id
log_analytics_workspace_id = var.log_analytics_workspace_id
enabled_log {
category = "FunctionAppLogs"
}
metric {
category = "AllMetrics"
}
}