|
| 1 | +resource "azurerm_service_plan" "service_plan" { |
| 2 | + name = "${local.prefix}-asp001" |
| 3 | + location = var.location |
| 4 | + resource_group_name = azurerm_resource_group.app_rg.name |
| 5 | + tags = var.tags |
| 6 | + |
| 7 | + # maximum_elastic_worker_count = 20 |
| 8 | + os_type = "Linux" |
| 9 | + per_site_scaling_enabled = false |
| 10 | + sku_name = "P1v3" |
| 11 | + worker_count = 3 |
| 12 | + zone_balancing_enabled = true |
| 13 | +} |
| 14 | + |
| 15 | +resource "azapi_resource" "function" { |
| 16 | + type = "Microsoft.Web/sites@2022-09-01" |
| 17 | + parent_id = azurerm_resource_group.app_rg.id |
| 18 | + name = "${local.prefix}-fctn001" |
| 19 | + location = var.location |
| 20 | + tags = var.tags |
| 21 | + identity { |
| 22 | + type = "SystemAssigned" |
| 23 | + } |
| 24 | + |
| 25 | + body = jsonencode({ |
| 26 | + kind = "functionapp,linux" |
| 27 | + properties = { |
| 28 | + clientAffinityEnabled = false |
| 29 | + clientCertEnabled = false |
| 30 | + clientCertMode = "Required" |
| 31 | + enabled = true |
| 32 | + hostNamesDisabled = false |
| 33 | + httpsOnly = true |
| 34 | + hyperV = false |
| 35 | + isXenon = false |
| 36 | + keyVaultReferenceIdentity = "SystemAssigned" |
| 37 | + publicNetworkAccess = "Disabled" |
| 38 | + redundancyMode = "None" |
| 39 | + reserved = true |
| 40 | + scmSiteAlsoStopped = false |
| 41 | + serverFarmId = azurerm_service_plan.service_plan.id |
| 42 | + storageAccountRequired = false |
| 43 | + virtualNetworkSubnetId = azapi_resource.subnet_function.id |
| 44 | + siteConfig = { |
| 45 | + autoHealEnabled = false |
| 46 | + acrUseManagedIdentityCreds = false |
| 47 | + alwaysOn = true |
| 48 | + appSettings = [ |
| 49 | + { |
| 50 | + name = "APPLICATIONINSIGHTS_CONNECTION_STRING" |
| 51 | + value = azurerm_application_insights.application_insights.connection_string |
| 52 | + }, |
| 53 | + { |
| 54 | + name = "APPINSIGHTS_INSTRUMENTATIONKEY" |
| 55 | + value = azurerm_application_insights.application_insights.instrumentation_key |
| 56 | + }, |
| 57 | + { |
| 58 | + name = "FUNCTIONS_EXTENSION_VERSION" |
| 59 | + value = "~4" |
| 60 | + }, |
| 61 | + { |
| 62 | + name = "FUNCTIONS_WORKER_RUNTIME" |
| 63 | + value = "python" |
| 64 | + }, |
| 65 | + { |
| 66 | + name = "WEBSITE_CONTENTOVERVNET" |
| 67 | + value = "1" |
| 68 | + }, |
| 69 | + { |
| 70 | + name = "AzureWebJobsStorage__accountName" |
| 71 | + value = azurerm_storage_account.storage.name |
| 72 | + } |
| 73 | + ] |
| 74 | + azureStorageAccounts = {} |
| 75 | + detailedErrorLoggingEnabled = true |
| 76 | + functionAppScaleLimit = 0 |
| 77 | + functionsRuntimeScaleMonitoringEnabled = false |
| 78 | + ftpsState = "FtpsOnly" |
| 79 | + http20Enabled = false |
| 80 | + ipSecurityRestrictionsDefaultAction = "Deny" |
| 81 | + linuxFxVersion = "Python|3.10" |
| 82 | + localMySqlEnabled = false |
| 83 | + loadBalancing = "LeastRequests" |
| 84 | + minTlsVersion = "1.2" |
| 85 | + minimumElasticInstanceCount = 0 |
| 86 | + numberOfWorkers = 1 |
| 87 | + preWarmedInstanceCount = 0 |
| 88 | + scmMinTlsVersion = "1.2" |
| 89 | + scmIpSecurityRestrictionsUseMain = false |
| 90 | + scmIpSecurityRestrictionsDefaultAction = "Deny" |
| 91 | + use32BitWorkerProcess = true |
| 92 | + vnetRouteAllEnabled = true |
| 93 | + vnetPrivatePortsCount = 0 |
| 94 | + webSocketsEnabled = false |
| 95 | + } |
| 96 | + } |
| 97 | + }) |
| 98 | +} |
| 99 | + |
| 100 | +data "azurerm_monitor_diagnostic_categories" "diagnostic_categories_function" { |
| 101 | + resource_id = azapi_resource.function.id |
| 102 | +} |
| 103 | + |
| 104 | +resource "azurerm_monitor_diagnostic_setting" "diagnostic_setting_function" { |
| 105 | + name = "logAnalytics" |
| 106 | + target_resource_id = azapi_resource.function.id |
| 107 | + log_analytics_workspace_id = azurerm_log_analytics_workspace.log_analytics_workspace.id |
| 108 | + |
| 109 | + dynamic "enabled_log" { |
| 110 | + iterator = entry |
| 111 | + for_each = data.azurerm_monitor_diagnostic_categories.diagnostic_categories_function.log_category_groups |
| 112 | + content { |
| 113 | + category_group = entry.value |
| 114 | + retention_policy { |
| 115 | + enabled = true |
| 116 | + days = 30 |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + dynamic "metric" { |
| 122 | + iterator = entry |
| 123 | + for_each = data.azurerm_monitor_diagnostic_categories.diagnostic_categories_function.metrics |
| 124 | + content { |
| 125 | + category = entry.value |
| 126 | + enabled = true |
| 127 | + retention_policy { |
| 128 | + enabled = true |
| 129 | + days = 30 |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments