-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.bicep
196 lines (170 loc) · 6.02 KB
/
solution.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
targetScope = 'subscription'
@description('The name of the compute gallery for managing the images.')
param computeGalleryName string
@description('The name of the deployment script for configuring an existing subnet.')
param deploymentScriptName string
@description('Determine whether to use an existing resource group.')
param existingResourceGroup bool
@description('The resource ID of an existing virtual network.')
param existingVirtualNetworkResourceId string = ''
@description('Indicates whether the image definition supports accelerated networking.')
param imageDefinitionIsAcceleratedNetworkSupported bool
@description('Indicates whether the image definition supports hibernation.')
param imageDefinitionIsHibernateSupported bool
@description('The name of the Image Definition for the Shared Image Gallery.')
param imageDefinitionName string
@allowed([
'ConfidentialVM'
'ConfidentialVMSupported'
'Standard'
'TrustedLaunch'
])
@description('The security type for the Image Definition.')
param imageDefinitionSecurityType string
@description('The offer of the marketplace image.')
param imageOffer string
@description('The publisher of the marketplace image.')
param imagePublisher string
@description('The SKU of the marketplace image.')
param imageSku string
@description('The location for the resources deployed in this solution.')
param location string = deployment().location
@description('The name of the resource group for the resources.')
param resourceGroupName string = 'rg-cit-dev-use'
@description('The name of the storage account for the imaging artifacts.')
param storageAccountName string
@description('The subnet name of an existing virtual network.')
param subnetName string
@description('The key-value pairs of tags for the resources.')
param tags object = {}
@description('DO NOT MODIFY THIS VALUE! The timestamp is needed to differentiate deployments for certain Azure resources and must be set using a parameter.')
param timestamp string = utcNow('yyyyMMddhhmmss')
@description('The name for the user assigned identity')
param userAssignedIdentityName string
var Roles = [
{
resourceGroup: split(existingVirtualNetworkResourceId, '/')[4]
name: 'Virtual Network Join'
description: 'Allow resources to join a subnet'
permissions: [
{
actions: [
'Microsoft.Network/virtualNetworks/read'
'Microsoft.Network/virtualNetworks/subnets/read'
'Microsoft.Network/virtualNetworks/subnets/join/action'
'Microsoft.Network/virtualNetworks/subnets/write' // Required to update the private link network policy
]
}
]
}
{
resourceGroup: resourceGroupName
name: 'Image Template Contributor'
description: 'Allow the creation and management of images'
permissions: [
{
actions: [
'Microsoft.Compute/galleries/read'
'Microsoft.Compute/galleries/images/read'
'Microsoft.Compute/galleries/images/versions/read'
'Microsoft.Compute/galleries/images/versions/write'
'Microsoft.Compute/images/read'
'Microsoft.Compute/images/write'
'Microsoft.Compute/images/delete'
]
}
]
}
]
resource rg 'Microsoft.Resources/resourceGroups@2019-10-01' = if (!existingResourceGroup) {
name: resourceGroupName
location: location
tags: contains(tags, 'Microsoft.Resources/resourceGroups') ? tags['Microsoft.Resources/resourceGroups'] : {}
properties: {}
}
resource roleDefinitions 'Microsoft.Authorization/roleDefinitions@2015-07-01' = [for i in range(0, length(Roles)): {
name: guid(Roles[i].name, subscription().id)
properties: {
roleName: '${Roles[i].name} (${subscription().subscriptionId})'
description: Roles[i].description
permissions: Roles[i].permissions
assignableScopes: [
subscription().id
]
}
}]
module userAssignedIdentity 'modules/userAssignedIdentity.bicep' = {
name: 'UserAssignedIdentity_${timestamp}'
scope: resourceGroup(resourceGroupName)
params: {
location: location
name: userAssignedIdentityName
tags: tags
}
dependsOn: [
rg
]
}
@batchSize(1)
module roleAssignments 'modules/roleAssignment.bicep' = [for i in range(0, length(Roles)): {
name: 'RoleAssignments_${i}_${timestamp}'
scope: resourceGroup(Roles[i].resourceGroup)
params: {
principalId: userAssignedIdentity.outputs.PrincipalId
roleDefinitionId: roleDefinitions[i].id
}
dependsOn: [
rg
]
}]
module computeGallery 'modules/computeGallery.bicep' = {
name: 'ComputeGallery_${timestamp}'
scope: resourceGroup(resourceGroupName)
params: {
computeGalleryName: computeGalleryName
imageDefinitionName: imageDefinitionName
imageDefinitionSecurityType: imageDefinitionSecurityType
imageOffer: imageOffer
imagePublisher: imagePublisher
imageSku: imageSku
location: location
tags: tags
imageDefinitionIsAcceleratedNetworkSupported: imageDefinitionIsAcceleratedNetworkSupported
imageDefinitionIsHibernateSupported: imageDefinitionIsHibernateSupported
}
dependsOn: [
rg
]
}
module networkPolicy 'modules/networkPolicy.bicep' = if (!(empty(subnetName)) && !(empty(existingVirtualNetworkResourceId))) {
name: 'NetworkPolicy_${timestamp}'
scope: resourceGroup(resourceGroupName)
params: {
deploymentScriptName: deploymentScriptName
location: location
subnetName: subnetName
tags: tags
timestamp: timestamp
userAssignedIdentityResourceId: userAssignedIdentity.outputs.ResourceId
virtualNetworkName: split(existingVirtualNetworkResourceId, '/')[8]
virtualNetworkResourceGroupName: split(existingVirtualNetworkResourceId, '/')[4]
}
dependsOn: [
rg
roleAssignments
]
}
module storage 'modules/storageAccount.bicep' = {
name: 'StorageAccount_${timestamp}'
scope: resourceGroup(resourceGroupName)
params: {
location: location
storageAccountName: storageAccountName
tags: tags
userAssignedIdentityPrincipalId: userAssignedIdentity.outputs.PrincipalId
userAssignedIdentityResourceId: userAssignedIdentity.outputs.ResourceId
}
dependsOn: [
rg
]
}