|
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" {} |
16 | 2 |
|
17 | 3 | data "azurerm_resource_group" "main" {
|
18 |
| - name = "${var.resource_group_name}" |
| 4 | + name = var.resource_group_name |
19 | 5 | }
|
20 | 6 |
|
21 | 7 | 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 |
26 | 12 | kind = "linux"
|
27 | 13 | reserved = true
|
28 | 14 |
|
29 | 15 | 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 |
32 | 18 | }
|
33 | 19 |
|
34 |
| - tags = "${var.tags}" |
| 20 | + tags = var.tags |
35 | 21 | }
|
36 | 22 |
|
37 | 23 | 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 |
42 | 30 |
|
43 |
| - https_only = "${var.https_only}" |
| 31 | + https_only = var.https_only |
44 | 32 |
|
45 | 33 | 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 |
51 | 41 | }
|
52 | 42 |
|
53 |
| - app_settings = "${merge(var.app_settings, local.app_settings)}" |
| 43 | + app_settings = merge(var.app_settings, local.secure_app_settings, local.app_settings) |
54 | 44 |
|
55 | 45 | 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 |
57 | 51 | }
|
58 | 52 |
|
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] |
60 | 96 | }
|
61 | 97 |
|
62 | 98 | 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 |
67 | 118 | }
|
0 commit comments