Skip to content

Commit a6a0cd3

Browse files
authored
Add vnet and environment setting to Pipeline Witness bicep (#8584)
1 parent 3e7ce10 commit a6a0cd3

8 files changed

Lines changed: 179 additions & 13 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"PipelineWitness": {
3+
"QueueStorageAccountUri": "https://pipelinewitnesstest.queue.core.windows.net",
4+
"BlobStorageAccountUri": "https://pipelinelogstest.blob.core.windows.net",
5+
"CosmosAccountUri": "https://pipelinewitnesstest.documents.azure.com"
6+
}
7+
}

tools/pipeline-witness/infrastructure/bicep/appResourceGroup.bicep

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,75 @@
11
param webAppName string
2+
param networkSecurityGroupName string
3+
param vnetName string
24
param appServicePlanName string
35
param appStorageAccountName string
6+
param aspEnvironment string
47
param cosmosAccountName string
58
param location string
9+
param vnetPrefix string
10+
param subnetPrefix string
611

712
var cosmosContributorRoleId = '00000000-0000-0000-0000-000000000002' // Built-in Contributor role
813

14+
resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2023-11-01' = {
15+
name: networkSecurityGroupName
16+
location: 'westus2'
17+
properties: {
18+
securityRules: []
19+
}
20+
}
21+
22+
resource vnet 'Microsoft.Network/virtualNetworks@2023-11-01' = {
23+
name: vnetName
24+
location: 'westus2'
25+
properties: {
26+
addressSpace: {
27+
addressPrefixes: [
28+
vnetPrefix
29+
]
30+
}
31+
virtualNetworkPeerings: []
32+
enableDdosProtection: false
33+
}
34+
}
35+
36+
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2023-11-01' = {
37+
parent: vnet
38+
name: 'default'
39+
properties: {
40+
addressPrefix: subnetPrefix
41+
networkSecurityGroup: {
42+
id: networkSecurityGroup.id
43+
}
44+
serviceEndpoints: [
45+
{
46+
service: 'Microsoft.Storage'
47+
locations: [
48+
'westus2'
49+
'westcentralus'
50+
]
51+
}
52+
{
53+
service: 'Microsoft.AzureCosmosDB'
54+
locations: [
55+
'*'
56+
]
57+
}
58+
]
59+
delegations: [
60+
{
61+
name: 'delegation'
62+
properties: {
63+
serviceName: 'Microsoft.Web/serverfarms'
64+
}
65+
type: 'Microsoft.Network/virtualNetworks/subnets/delegations'
66+
}
67+
]
68+
privateEndpointNetworkPolicies: 'Disabled'
69+
privateLinkServiceNetworkPolicies: 'Enabled'
70+
}
71+
}
72+
973
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
1074
name: appServicePlanName
1175
location: location
@@ -28,6 +92,8 @@ resource webApp 'Microsoft.Web/sites@2022-03-01' = {
2892
linuxFxVersion: 'DOTNETCORE|6.0'
2993
}
3094
httpsOnly: true
95+
virtualNetworkSubnetId: subnet.id
96+
publicNetworkAccess: 'Enabled'
3197
}
3298
identity: {
3399
type: 'SystemAssigned'
@@ -46,13 +112,12 @@ resource appStorageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
46112
defaultToOAuthAuthentication: false
47113
allowCrossTenantReplication: true
48114
minimumTlsVersion: 'TLS1_2'
49-
allowBlobPublicAccess: true
50-
allowSharedKeyAccess: true
115+
allowBlobPublicAccess: false
116+
allowSharedKeyAccess: false
51117
networkAcls: {
52118
bypass: 'AzureServices'
53-
virtualNetworkRules: []
54-
ipRules: []
55-
defaultAction: 'Allow'
119+
virtualNetworkRules: [{ id: subnet.id }]
120+
defaultAction: 'Deny'
56121
}
57122
supportsHttpsTrafficOnly: true
58123
encryption: {
@@ -120,16 +185,18 @@ resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2024-02-15-preview
120185
publicNetworkAccess: 'Enabled'
121186
enableAutomaticFailover: false
122187
enableMultipleWriteLocations: false
123-
isVirtualNetworkFilterEnabled: false
124-
virtualNetworkRules: []
188+
isVirtualNetworkFilterEnabled: true
189+
virtualNetworkRules: [{
190+
id: subnet.id
191+
}]
125192
disableKeyBasedMetadataWriteAccess: false
126193
enableFreeTier: false
127194
enableAnalyticalStorage: false
128195
analyticalStorageConfiguration: {}
129196
databaseAccountOfferType: 'Standard'
130197
enableMaterializedViews: false
131198
networkAclBypass: 'None'
132-
disableLocalAuth: false
199+
disableLocalAuth: true
133200
enablePartitionMerge: false
134201
enablePerRegionPerPartitionAutoscale: false
135202
enableBurstCapacity: false
@@ -275,4 +342,18 @@ resource sqlRoleAssignment 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignm
275342
}
276343
}
277344

345+
// Use a module to merge the current app settings with the new ones to prevent overwritting the app insights configured settings
346+
module appSettings 'appSettings.bicep' = {
347+
name: '${webAppName}-appsettings'
348+
params: {
349+
webAppName: webApp.name
350+
// Get the current appsettings
351+
currentAppSettings: list(resourceId('Microsoft.Web/sites/config', webApp.name, 'appsettings'), '2022-03-01').properties
352+
appSettings: {
353+
ASPNETCORE_ENVIRONMENT: aspEnvironment
354+
}
355+
}
356+
}
357+
278358
output appIdentityPrincipalId string = webApp.identity.principalId
359+
output subnetId string = subnet.id
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
param webAppName string
2+
param appSettings object
3+
param currentAppSettings object
4+
5+
resource webApp 'Microsoft.Web/sites@2022-03-01' existing = {
6+
name: webAppName
7+
}
8+
9+
resource siteconfig 'Microsoft.Web/sites/config@2022-03-01' = {
10+
parent: webApp
11+
name: 'appsettings'
12+
properties: union(currentAppSettings, appSettings)
13+
}

tools/pipeline-witness/infrastructure/bicep/logsResourceGroup.bicep

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ param logsStorageAccountName string
33
param kustoClusterName string
44
param kustoDatabaseName string
55
param webAppName string
6+
param subnetId string
67
param appIdentityPrincipalId string
78

89
var tables = [
@@ -54,13 +55,12 @@ resource logsStorageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
5455
defaultToOAuthAuthentication: false
5556
allowCrossTenantReplication: true
5657
minimumTlsVersion: 'TLS1_2'
57-
allowBlobPublicAccess: true
58-
allowSharedKeyAccess: true
58+
allowBlobPublicAccess: false
59+
allowSharedKeyAccess: false
5960
networkAcls: {
6061
bypass: 'AzureServices'
61-
virtualNetworkRules: []
62-
ipRules: []
63-
defaultAction: 'Allow'
62+
virtualNetworkRules: [{ id: subnetId }]
63+
defaultAction: 'Deny'
6464
}
6565
supportsHttpsTrafficOnly: true
6666
encryption: {
@@ -180,6 +180,7 @@ resource kustoCluster 'Microsoft.Kusto/Clusters@2022-02-01' = {
180180
enableAutoStop: false
181181
publicIPType: 'IPv4'
182182
}
183+
183184
resource database 'Databases' = {
184185
name: kustoDatabaseName
185186
location: location
@@ -188,6 +189,14 @@ resource kustoCluster 'Microsoft.Kusto/Clusters@2022-02-01' = {
188189
hotCachePeriod: 'P31D'
189190
}
190191
}
192+
193+
resource managedEndpoint 'managedPrivateEndpoints' = {
194+
name: logsStorageAccountName
195+
properties: {
196+
groupId: 'blob'
197+
privateLinkResourceId: logsStorageAccount.id
198+
}
199+
}
191200
}
192201

193202
// Resources per table

tools/pipeline-witness/infrastructure/bicep/parameters.production.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"appStorageAccountName": {
2121
"value": "pipelinewitnessprod"
2222
},
23+
"aspEnvironment": {
24+
"value": "production"
25+
},
2326
"logsResourceGroupName": {
2427
"value": "pipelinelogs"
2528
},
@@ -31,6 +34,18 @@
3134
},
3235
"kustoDatabaseName": {
3336
"value": "Pipelines"
37+
},
38+
"networkSecurityGroupName": {
39+
"value": "pipelinewitnessprod"
40+
},
41+
"vnetName": {
42+
"value": "pipelinewitnessprod"
43+
},
44+
"vnetPrefix": {
45+
"value": "10.9.0.0/16"
46+
},
47+
"subnetPrefix": {
48+
"value": "10.9.0.0/24"
3449
}
3550
}
3651
}

tools/pipeline-witness/infrastructure/bicep/parameters.staging.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"appStorageAccountName": {
2121
"value": "pipelinewitnessstaging"
2222
},
23+
"aspEnvironment": {
24+
"value": "staging"
25+
},
2326
"logsResourceGroupName": {
2427
"value": "pipelinelogs"
2528
},
@@ -31,6 +34,18 @@
3134
},
3235
"kustoDatabaseName": {
3336
"value": "Staging"
37+
},
38+
"networkSecurityGroupName": {
39+
"value": "pipelinewitnessstaging"
40+
},
41+
"vnetName": {
42+
"value": "pipelinewitnessstaging"
43+
},
44+
"vnetPrefix": {
45+
"value": "10.8.0.0/16"
46+
},
47+
"subnetPrefix": {
48+
"value": "10.8.0.0/24"
3449
}
3550
}
3651
}

tools/pipeline-witness/infrastructure/bicep/parameters.test.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"appStorageAccountName": {
2121
"value": "pipelinewitnesstest"
2222
},
23+
"aspEnvironment": {
24+
"value": "test"
25+
},
2326
"logsResourceGroupName": {
2427
"value": "pipelinelogstest"
2528
},
@@ -31,6 +34,18 @@
3134
},
3235
"kustoDatabaseName": {
3336
"value": "test"
37+
},
38+
"networkSecurityGroupName": {
39+
"value": "pipelinewitnesstest"
40+
},
41+
"vnetName": {
42+
"value": "pipelinewitnesstest"
43+
},
44+
"vnetPrefix": {
45+
"value": "10.7.0.0/16"
46+
},
47+
"subnetPrefix": {
48+
"value": "10.7.0.0/24"
3449
}
3550
}
3651
}

tools/pipeline-witness/infrastructure/bicep/resourceGroups.bicep

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ param location string
55
param appResourceGroupName string
66
param appServicePlanName string
77
param webAppName string
8+
param networkSecurityGroupName string
9+
param vnetName string
10+
param vnetPrefix string
11+
param subnetPrefix string
812
param cosmosAccountName string
913
param appStorageAccountName string
14+
param aspEnvironment string
1015

1116
param logsResourceGroupName string
1217
param logsStorageAccountName string
@@ -25,9 +30,14 @@ module pipelineWitness 'appResourceGroup.bicep' = {
2530
params: {
2631
location: location
2732
appServicePlanName: appServicePlanName
33+
vnetPrefix: vnetPrefix
34+
subnetPrefix: subnetPrefix
2835
webAppName: webAppName
2936
cosmosAccountName: cosmosAccountName
3037
appStorageAccountName: appStorageAccountName
38+
aspEnvironment: aspEnvironment
39+
networkSecurityGroupName: networkSecurityGroupName
40+
vnetName: vnetName
3141
}
3242
}
3343

@@ -49,5 +59,6 @@ module pipelineLogs 'logsResourceGroup.bicep' = {
4959
kustoDatabaseName: kustoDatabaseName
5060
webAppName: webAppName
5161
appIdentityPrincipalId: pipelineWitness.outputs.appIdentityPrincipalId
62+
subnetId: pipelineWitness.outputs.subnetId
5263
}
5364
}

0 commit comments

Comments
 (0)