|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +// ---------------------------------------------------------------------------- |
| 5 | +// Resource-group-scoped resources: Storage, App Insights, Function App. |
| 6 | +// ---------------------------------------------------------------------------- |
| 7 | + |
| 8 | +@minLength(1) |
| 9 | +param environmentName string |
| 10 | + |
| 11 | +@minLength(1) |
| 12 | +param location string |
| 13 | + |
| 14 | +param tags object = {} |
| 15 | + |
| 16 | +param connectorRuntimeUrl string = '' |
| 17 | + |
| 18 | +@secure() |
| 19 | +param connectorToken string = '' |
| 20 | + |
| 21 | +var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) |
| 22 | +var storageAccountName = take('st${replace(resourceToken, '-', '')}', 24) |
| 23 | +var planName = 'plan-${environmentName}-${resourceToken}' |
| 24 | +var functionAppName = 'func-${environmentName}-${resourceToken}' |
| 25 | +var appInsightsName = 'appi-${environmentName}-${resourceToken}' |
| 26 | +var logAnalyticsName = 'log-${environmentName}-${resourceToken}' |
| 27 | + |
| 28 | +resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = { |
| 29 | + name: storageAccountName |
| 30 | + location: location |
| 31 | + kind: 'StorageV2' |
| 32 | + sku: { |
| 33 | + name: 'Standard_LRS' |
| 34 | + } |
| 35 | + properties: { |
| 36 | + minimumTlsVersion: 'TLS1_2' |
| 37 | + allowBlobPublicAccess: false |
| 38 | + supportsHttpsTrafficOnly: true |
| 39 | + } |
| 40 | + tags: tags |
| 41 | +} |
| 42 | + |
| 43 | +resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = { |
| 44 | + name: logAnalyticsName |
| 45 | + location: location |
| 46 | + properties: { |
| 47 | + sku: { |
| 48 | + name: 'PerGB2018' |
| 49 | + } |
| 50 | + retentionInDays: 30 |
| 51 | + } |
| 52 | + tags: tags |
| 53 | +} |
| 54 | + |
| 55 | +resource appInsights 'Microsoft.Insights/components@2020-02-02' = { |
| 56 | + name: appInsightsName |
| 57 | + location: location |
| 58 | + kind: 'web' |
| 59 | + properties: { |
| 60 | + Application_Type: 'web' |
| 61 | + WorkspaceResourceId: logAnalytics.id |
| 62 | + } |
| 63 | + tags: tags |
| 64 | +} |
| 65 | + |
| 66 | +resource appPlan 'Microsoft.Web/serverfarms@2023-12-01' = { |
| 67 | + name: planName |
| 68 | + location: location |
| 69 | + kind: 'linux' |
| 70 | + sku: { |
| 71 | + name: 'Y1' |
| 72 | + tier: 'Dynamic' |
| 73 | + } |
| 74 | + properties: { |
| 75 | + reserved: true |
| 76 | + } |
| 77 | + tags: tags |
| 78 | +} |
| 79 | + |
| 80 | +resource functionApp 'Microsoft.Web/sites@2023-12-01' = { |
| 81 | + name: functionAppName |
| 82 | + location: location |
| 83 | + kind: 'functionapp,linux' |
| 84 | + identity: { |
| 85 | + type: 'SystemAssigned' |
| 86 | + } |
| 87 | + properties: { |
| 88 | + serverFarmId: appPlan.id |
| 89 | + httpsOnly: true |
| 90 | + siteConfig: { |
| 91 | + linuxFxVersion: 'Node|20' |
| 92 | + ftpsState: 'FtpsOnly' |
| 93 | + minTlsVersion: '1.2' |
| 94 | + appSettings: [ |
| 95 | + { |
| 96 | + name: 'AzureWebJobsStorage' |
| 97 | + value: 'DefaultEndpointsProtocol=https;AccountName=${storage.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storage.listKeys().keys[0].value}' |
| 98 | + } |
| 99 | + { |
| 100 | + name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING' |
| 101 | + value: 'DefaultEndpointsProtocol=https;AccountName=${storage.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storage.listKeys().keys[0].value}' |
| 102 | + } |
| 103 | + { |
| 104 | + name: 'WEBSITE_CONTENTSHARE' |
| 105 | + value: toLower(functionAppName) |
| 106 | + } |
| 107 | + { |
| 108 | + name: 'FUNCTIONS_EXTENSION_VERSION' |
| 109 | + value: '~4' |
| 110 | + } |
| 111 | + { |
| 112 | + name: 'FUNCTIONS_WORKER_RUNTIME' |
| 113 | + value: 'node' |
| 114 | + } |
| 115 | + { |
| 116 | + name: 'WEBSITE_NODE_DEFAULT_VERSION' |
| 117 | + value: '~20' |
| 118 | + } |
| 119 | + { |
| 120 | + name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' |
| 121 | + value: appInsights.properties.ConnectionString |
| 122 | + } |
| 123 | + { |
| 124 | + name: 'ConnectorRuntimeUrl' |
| 125 | + value: connectorRuntimeUrl |
| 126 | + } |
| 127 | + { |
| 128 | + name: 'ConnectorToken' |
| 129 | + value: connectorToken |
| 130 | + } |
| 131 | + ] |
| 132 | + } |
| 133 | + } |
| 134 | + tags: union(tags, { |
| 135 | + 'azd-service-name': 'api' |
| 136 | + }) |
| 137 | +} |
| 138 | + |
| 139 | +output functionAppName string = functionApp.name |
| 140 | +output functionAppHostname string = functionApp.properties.defaultHostName |
0 commit comments