|
| 1 | +config sqlAdmin string { |
| 2 | + default = "pulumi" |
| 3 | +} |
| 4 | + |
| 5 | +blobAccessToken = secret(invoke("azure-native:storage:listStorageAccountServiceSAS", { |
| 6 | + accountName = sa.name, |
| 7 | + protocols = "https", |
| 8 | + sharedAccessStartTime = "2022-01-01", |
| 9 | + sharedAccessExpiryTime = "2030-01-01", |
| 10 | + resource = "c", |
| 11 | + resourceGroupName = appservicegroup.name, |
| 12 | + permissions = "r", |
| 13 | + canonicalizedResource = "/blob/${sa.name}/${container.name}", |
| 14 | + contentType = "application/json", |
| 15 | + cacheControl = "max-age=5", |
| 16 | + contentDisposition = "inline", |
| 17 | + contentEncoding = "deflate" |
| 18 | +}).serviceSasToken) |
| 19 | + |
| 20 | +resource appservicegroup "azure-native:resources:ResourceGroup" { |
| 21 | + __logicalName = "appservicegroup" |
| 22 | +} |
| 23 | + |
| 24 | +resource sa "azure-native:storage:StorageAccount" { |
| 25 | + __logicalName = "sa" |
| 26 | + resourceGroupName = appservicegroup.name |
| 27 | + kind = "StorageV2" |
| 28 | + sku = { |
| 29 | + name = "Standard_LRS" |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +resource appserviceplan "azure-native:web:AppServicePlan" { |
| 34 | + __logicalName = "appserviceplan" |
| 35 | + resourceGroupName = appservicegroup.name |
| 36 | + kind = "App" |
| 37 | + sku = { |
| 38 | + name = "B1", |
| 39 | + tier = "Basic" |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +resource container "azure-native:storage:BlobContainer" { |
| 44 | + __logicalName = "container" |
| 45 | + resourceGroupName = appservicegroup.name |
| 46 | + accountName = sa.name |
| 47 | + publicAccess = "None" |
| 48 | +} |
| 49 | + |
| 50 | +resource blob "azure-native:storage:Blob" { |
| 51 | + __logicalName = "blob" |
| 52 | + resourceGroupName = appservicegroup.name |
| 53 | + accountName = sa.name |
| 54 | + containerName = container.name |
| 55 | + type = "Block" |
| 56 | + source = fileArchive("./www") |
| 57 | +} |
| 58 | + |
| 59 | +resource appInsights "azure-native:insights:Component" { |
| 60 | + __logicalName = "appInsights" |
| 61 | + resourceGroupName = appservicegroup.name |
| 62 | + applicationType = "web" |
| 63 | + kind = "web" |
| 64 | +} |
| 65 | + |
| 66 | +resource sqlPassword "random:index/randomPassword:RandomPassword" { |
| 67 | + __logicalName = "sqlPassword" |
| 68 | + length = 16 |
| 69 | + special = true |
| 70 | +} |
| 71 | + |
| 72 | +resource sqlServer "azure-native:sql:Server" { |
| 73 | + __logicalName = "sqlServer" |
| 74 | + resourceGroupName = appservicegroup.name |
| 75 | + administratorLogin = sqlAdmin |
| 76 | + administratorLoginPassword = sqlPassword.result |
| 77 | + version = "12.0" |
| 78 | +} |
| 79 | + |
| 80 | +resource db "azure-native:sql:Database" { |
| 81 | + __logicalName = "db" |
| 82 | + resourceGroupName = appservicegroup.name |
| 83 | + serverName = sqlServer.name |
| 84 | + sku = { |
| 85 | + name = "S0" |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +resource app "azure-native:web:WebApp" { |
| 90 | + __logicalName = "app" |
| 91 | + resourceGroupName = appservicegroup.name |
| 92 | + serverFarmId = appserviceplan.id |
| 93 | + siteConfig = { |
| 94 | + appSettings = [ |
| 95 | + { |
| 96 | + name = "WEBSITE_RUN_FROM_PACKAGE", |
| 97 | + value = "https://${sa.name}.blob.core.windows.net/${container.name}/${blob.name}?${blobAccessToken}" |
| 98 | + }, |
| 99 | + { |
| 100 | + name = "APPINSIGHTS_INSTRUMENTATIONKEY", |
| 101 | + value = appInsights.instrumentationKey |
| 102 | + }, |
| 103 | + { |
| 104 | + name = "APPLICATIONINSIGHTS_CONNECTION_STRING", |
| 105 | + value = "InstrumentationKey=${appInsights.instrumentationKey}" |
| 106 | + }, |
| 107 | + { |
| 108 | + name = "ApplicationInsightsAgent_EXTENSION_VERSION", |
| 109 | + value = "~2" |
| 110 | + } |
| 111 | + ], |
| 112 | + connectionStrings = [{ |
| 113 | + name = "db", |
| 114 | + type = "SQLAzure", |
| 115 | + connectionString = "Server= tcp:${sqlServer.name}.database.windows.net;initial catalog=${db.name};userID=${sqlAdmin};password=${sqlPassword.result};Min Pool Size=0;Max Pool Size=30;Persist Security Info=true;" |
| 116 | + }] |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +output endpoint { |
| 121 | + __logicalName = "endpoint" |
| 122 | + value = app.defaultHostName |
| 123 | +} |
0 commit comments