Skip to content

Commit 63ba48c

Browse files
committed
Merge branch 'dev'
2 parents 84c4bc1 + f0c3e95 commit 63ba48c

File tree

4 files changed

+290
-143
lines changed

4 files changed

+290
-143
lines changed

main.tf

Lines changed: 91 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,118 @@
1-
locals {
2-
app_service_plan_id = "${var.app_service_plan_id != "" ? var.app_service_plan_id : element(coalescelist(azurerm_app_service_plan.main.*.id, list("")), 0)}"
3-
4-
container_type = "${upper(var.container_type)}"
5-
container_config = "${base64encode(var.container_config)}"
6-
7-
app_settings = {
8-
"WEBSITES_CONTAINER_START_TIME_LIMIT" = "${var.start_time_limit}"
9-
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "${var.enable_storage}"
10-
"WEBSITES_PORT" = "${var.port}"
11-
"DOCKER_REGISTRY_SERVER_USERNAME" = "${var.docker_registry_username}"
12-
"DOCKER_REGISTRY_SERVER_URL" = "${var.docker_registry_url}"
13-
"DOCKER_REGISTRY_SERVER_PASSWORD" = "${var.docker_registry_password}"
14-
}
15-
}
1+
data "azurerm_client_config" "main" {}
162

173
data "azurerm_resource_group" "main" {
18-
name = "${var.resource_group_name}"
4+
name = var.resource_group_name
195
}
206

217
resource "azurerm_app_service_plan" "main" {
22-
count = "${var.app_service_plan_id == "" ? 1 : 0}"
23-
name = "${var.name}-plan"
24-
location = "${data.azurerm_resource_group.main.location}"
25-
resource_group_name = "${data.azurerm_resource_group.main.name}"
8+
count = local.plan.id == "" ? 1 : 0
9+
name = coalesce(local.plan.name, local.default_plan_name)
10+
location = data.azurerm_resource_group.main.location
11+
resource_group_name = data.azurerm_resource_group.main.name
2612
kind = "linux"
2713
reserved = true
2814

2915
sku {
30-
tier = "${var.sku_tier}"
31-
size = "${var.sku_size}"
16+
tier = local.sku_tiers[local.plan.sku_size]
17+
size = local.plan.sku_size
3218
}
3319

34-
tags = "${var.tags}"
20+
tags = var.tags
3521
}
3622

3723
resource "azurerm_app_service" "main" {
38-
name = "${var.name}"
39-
location = "${data.azurerm_resource_group.main.location}"
40-
resource_group_name = "${data.azurerm_resource_group.main.name}"
41-
app_service_plan_id = "${local.app_service_plan_id}"
24+
name = var.name
25+
location = data.azurerm_resource_group.main.location
26+
resource_group_name = data.azurerm_resource_group.main.name
27+
app_service_plan_id = local.plan_id
28+
29+
client_affinity_enabled = false
4230

43-
https_only = "${var.https_only}"
31+
https_only = var.https_only
4432

4533
site_config {
46-
always_on = "${var.always_on}"
47-
app_command_line = "${var.command}"
48-
ftps_state = "${var.ftps_state}"
49-
ip_restriction = "${var.ip_restrictions}"
50-
linux_fx_version = "${local.container_type}|${local.container_type == "DOCKER" ? var.container_image : local.container_config}"
34+
always_on = local.always_on
35+
app_command_line = var.command
36+
ftps_state = var.ftps_state
37+
ip_restriction = local.ip_restrictions
38+
linux_fx_version = local.linux_fx_version
39+
40+
use_32_bit_worker_process = local.use_32_bit_worker_process
5141
}
5242

53-
app_settings = "${merge(var.app_settings, local.app_settings)}"
43+
app_settings = merge(var.app_settings, local.secure_app_settings, local.app_settings)
5444

5545
identity {
56-
type = "SystemAssigned"
46+
type = (local.identity.enabled ?
47+
(local.identity.ids != null ? "SystemAssigned, UserAssigned" : "SystemAssigned") :
48+
"None"
49+
)
50+
identity_ids = local.identity.ids
5751
}
5852

59-
tags = "${var.tags}"
53+
dynamic "storage_account" {
54+
for_each = local.storage_mounts
55+
iterator = s
56+
57+
content {
58+
name = s.value.name
59+
type = s.value.share_name != "" ? "AzureFiles" : "AzureBlob"
60+
account_name = s.value.account_name
61+
share_name = s.value.share_name != "" ? s.value.share_name : s.value.container_name
62+
access_key = s.value.access_key
63+
mount_path = s.value.mount_path
64+
}
65+
}
66+
67+
dynamic "auth_settings" {
68+
for_each = local.auth.enabled ? [local.auth] : []
69+
70+
content {
71+
enabled = auth_settings.value.enabled
72+
issuer = format("https://sts.windows.net/%s/", data.azurerm_client_config.main.tenant_id)
73+
token_store_enabled = local.auth.token_store_enabled
74+
additional_login_params = {
75+
response_type = "code id_token"
76+
resource = local.auth.active_directory.client_id
77+
}
78+
default_provider = "AzureActiveDirectory"
79+
80+
dynamic "active_directory" {
81+
for_each = [auth_settings.value.active_directory]
82+
83+
content {
84+
client_id = active_directory.value.client_id
85+
client_secret = active_directory.value.client_secret
86+
allowed_audiences = formatlist("https://%s", concat(
87+
[format("%s.azurewebsites.net", var.name)], var.custom_hostnames))
88+
}
89+
}
90+
}
91+
}
92+
93+
tags = var.tags
94+
95+
depends_on = [azurerm_key_vault_secret.main]
6096
}
6197

6298
resource "azurerm_app_service_custom_hostname_binding" "main" {
63-
count = "${length(var.custom_hostnames)}"
64-
hostname = "${var.custom_hostnames[count.index]}"
65-
app_service_name = "${azurerm_app_service.main.name}"
66-
resource_group_name = "${data.azurerm_resource_group.main.name}"
99+
count = length(var.custom_hostnames)
100+
hostname = var.custom_hostnames[count.index]
101+
app_service_name = azurerm_app_service.main.name
102+
resource_group_name = data.azurerm_resource_group.main.name
103+
}
104+
105+
resource "azurerm_key_vault_access_policy" "main" {
106+
count = length(var.secure_app_settings) > 0 ? 1 : 0
107+
key_vault_id = var.key_vault_id
108+
tenant_id = azurerm_app_service.main.identity[0].tenant_id
109+
object_id = azurerm_app_service.main.identity[0].principal_id
110+
secret_permissions = ["get"]
111+
}
112+
113+
resource "azurerm_key_vault_secret" "main" {
114+
count = length(local.key_vault_secrets)
115+
key_vault_id = var.key_vault_id
116+
name = local.key_vault_secrets[count.index].name
117+
value = local.key_vault_secrets[count.index].value
67118
}

outputs.tf

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
output "id" {
2-
value = "${azurerm_app_service.main.id}"
3-
2+
value = azurerm_app_service.main.id
43
description = "The ID of the App Service."
54
}
65

7-
output "hostname" {
8-
value = "${azurerm_app_service.main.default_site_hostname}"
6+
output "name" {
7+
value = azurerm_app_service.main.name
8+
description = "The name of the App Service."
9+
}
910

11+
output "hostname" {
12+
value = azurerm_app_service.main.default_site_hostname
1013
description = "The default hostname for the App Service."
1114
}
1215

1316
output "outbound_ips" {
14-
value = "${split(",", azurerm_app_service.main.outbound_ip_addresses)}"
15-
17+
value = split(",", azurerm_app_service.main.outbound_ip_addresses)
1618
description = "A list of outbound IP addresses for the App Service."
1719
}
1820

1921
output "possible_outbound_ips" {
20-
value = "${split(",", azurerm_app_service.main.possible_outbound_ip_addresses)}"
21-
22+
value = split(",", azurerm_app_service.main.possible_outbound_ip_addresses)
2223
description = "A list of possible outbound IP addresses for the App Service. Superset of outbound_ips."
2324
}
2425

25-
output "principal_id" {
26-
value = "${azurerm_app_service.main.identity.0.principal_id}"
27-
description = "The principal ID for the system-assigned identity associated with the App Service."
26+
output "plan" {
27+
value = {
28+
id = azurerm_app_service.main.app_service_plan_id
29+
}
30+
description = "A mapping of App Service plan properties."
31+
}
32+
33+
output "identity" {
34+
value = {
35+
principal_id = azurerm_app_service.main.identity[0].principal_id
36+
ids = azurerm_app_service.main.identity[0].identity_ids
37+
}
38+
description = "A mapping og identity properties for the web app."
2839
}

0 commit comments

Comments
 (0)