Skip to content

Commit 1ab6329

Browse files
committed
Rework lower-level bicep files to support new storage account type and parameter
1 parent 528f592 commit 1ab6329

5 files changed

Lines changed: 65 additions & 50 deletions

File tree

bicep/ccw.bicep

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,18 @@ module ccwBastion './bastion.bicep' = if (deploy_bastion) {
112112
}
113113
}
114114

115-
param cyclecloudBaseImage string = 'azurecyclecloud:azure-cyclecloud:cyclecloud8-gen2:8.7.220250630'
115+
var vmMiName = 'ccwCycleCloudVirtualMachineManagedIdentity'
116+
module ccwVirtualMachineManagedIdentity './vmManagedIdentity.bicep' = if (!infrastructureOnly && storageAccount.type == 'new') {
117+
name: vmMiName
118+
params: {
119+
name: vmMiName
120+
location: location
121+
tags: getTags('Microsoft.ManagedIdentity/userAssignedIdentities', tags)
122+
}
123+
}
116124

125+
param cyclecloudBaseImage string = 'azurecyclecloud:azure-cyclecloud:cyclecloud8-gen2:8.7.220250630'
126+
var ccwVirtualMachineManagedIdentityId = !infrastructureOnly ? ( storageAccount.type == 'new' ? ccwVirtualMachineManagedIdentity!.outputs.managedIdentityId : storageAccount.vmManagedIdentityId) : ''
117127
module ccwVM './vm.bicep' = if (!infrastructureOnly) {
118128
name: 'ccwVM-cyclecloud'
119129
params: {
@@ -151,49 +161,60 @@ module ccwVM './vm.bicep' = if (!infrastructureOnly) {
151161
createOption: split(cyclecloudBaseImage, ':')[0] == 'azurecyclecloud' ? 'FromImage' : 'Empty'
152162
}
153163
]
164+
managedIdentityId: ccwVirtualMachineManagedIdentityId
154165
}
155166
dependsOn: [
156167
ccwNetwork
157168
]
158169
}
159170

160-
var miName = 'ccwLockerManagedIdentity'
161-
module ccwManagedIdentity 'mi.bicep' = if (!infrastructureOnly) {
162-
name: miName
171+
module ccwNewStorageAccount './storage-new.bicep' = if (storageAccount.type == 'new') {
172+
name: 'ccwNewStorageAccount'
163173
params: {
164-
name: miName
165174
location: location
166-
storageAccountName: ccwStorage.outputs.storageAccountName
167-
tags: getTags('Microsoft.ManagedIdentity/userAssignedIdentities', tags)
175+
tags: getTags('Microsoft.Storage/storageAccounts', tags)
168176
}
169177
}
178+
var storageAccountName = storageAccount.type == 'existing' ? split(storageAccount.storageAccountId, '/')[8] : ccwNewStorageAccount!.outputs.storageAccountName
170179

171-
module ccwRoleAssignments './vmRoleAssignments.bicep' = if (!infrastructureOnly) {
172-
name: 'ccwRoleFor-${ccVMName}-${location}'
173-
scope: subscription()
180+
module ccwStorageNetworking './storage-networking.bicep' = {
181+
name: 'ccwStorageAccountNetworking'
174182
params: {
175-
roles: [
176-
'Contributor'
177-
'Storage Account Contributor'
178-
'Storage Blob Data Contributor'
179-
]
180-
principalId: ccwVM.outputs.principalId
183+
location: location
184+
saName: storageAccountName
185+
tags: getTags('Microsoft.Storage/storageAccounts', tags)
186+
subnetId: subnets.cyclecloud.id
187+
storagePrivateDnsZone: storagePrivateDnsZone
181188
}
182-
dependsOn: [
183-
ccwVM
184-
]
185189
}
186190

187-
module ccwStorage './storage.bicep' = {
188-
name: 'ccwStorage'
191+
var vmssMiName = 'ccwLockerManagedIdentity'
192+
module ccwVMSSManagedIdentity 'vmssManagedIdentity.bicep' = if (!infrastructureOnly && storageAccount.type == 'new') {
193+
name: vmssMiName
189194
params: {
195+
name: vmssMiName
190196
location: location
191-
tags: getTags('Microsoft.Storage/storageAccounts', tags)
192-
saName: 'ccwstorage${uniqueString(az.resourceGroup().id)}'
193-
subnetId: subnets.cyclecloud.id
194-
storagePrivateDnsZone: storagePrivateDnsZone
197+
storageAccountName: storageAccountName
198+
tags: getTags('Microsoft.ManagedIdentity/userAssignedIdentities', tags)
195199
}
196200
}
201+
var vmssManagedIdentityId = !infrastructureOnly ? ( storageAccount.type == 'new' ? ccwVMSSManagedIdentity!.outputs.managedIdentityId : storageAccount.vmssManagedIdentityId) : ''
202+
203+
// module ccwRoleAssignments './vmRoleAssignments.bicep' = if (!infrastructureOnly) {
204+
// name: 'ccwRoleFor-${ccVMName}-${location}'
205+
// scope: subscription()
206+
// params: {
207+
// roles: [
208+
// 'Contributor'
209+
// 'Storage Account Contributor'
210+
// 'Storage Blob Data Contributor'
211+
// ]
212+
// principalId: ccwVM.outputs.principalId
213+
// }
214+
// dependsOn: [
215+
// ccwVM
216+
// ]
217+
// }
197218

198219
var create_database = contains(slurmSettings, 'databaseAdminPassword')
199220
var db_name = 'ccw-mysqldb-${uniqueString(az.resourceGroup().id)}'
@@ -313,9 +334,10 @@ output filerInfoFinal types.filerInfo_t = {
313334
}
314335
}
315336

316-
output cyclecloudPrincipalId string = infrastructureOnly ? '' : ccwVM.outputs.principalId
337+
output cyclecloudPrincipalId string = infrastructureOnly ? '' : ccwVM!.outputs.principalId
317338

318-
output managedIdentityId string = infrastructureOnly ? '' : ccwManagedIdentity.outputs.managedIdentityId
339+
// MI for VMSS
340+
output managedIdentityId string = vmssManagedIdentityId
319341

320342
// Automatically inject the ccw and pyxis cluster init specs
321343

@@ -369,7 +391,7 @@ var clusterNameCleaned = join(clusterNameArrCleaned,'')
369391

370392
output resourceGroup string = resourceGroup
371393
output location string = location
372-
output storageAccountName string = ccwStorage.outputs.storageAccountName
394+
output storageAccountName string = storageAccountName
373395
output clusterName string = clusterNameCleaned
374396
output publicKey string = publicKey
375397
output adminUsername string = adminUsername
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,8 @@ var privateDnsZoneResourceGroup = split(privateDnsZoneId, '/')[4]
1212
var createVnetLink = storagePrivateDnsZone.type == 'existing' ? storagePrivateDnsZone.vnetLink : storagePrivateDnsZone.type == 'new'
1313
var vnetLinkScope = contains(storagePrivateDnsZone,'id') ? split(privateDnsZoneId, '/')[4] : az.resourceGroup().name
1414

15-
resource storageAccount 'Microsoft.Storage/storageAccounts@2024-01-01' = {
15+
resource storageAccount 'Microsoft.Storage/storageAccounts@2024-01-01' existing = {
1616
name: saName
17-
location: location
18-
tags: tags
19-
sku: {
20-
name: 'Standard_LRS'
21-
}
22-
kind: 'StorageV2'
23-
properties:{
24-
accessTier: 'Hot'
25-
minimumTlsVersion: 'TLS1_2'
26-
allowSharedKeyAccess: false
27-
publicNetworkAccess: 'Disabled'
28-
allowBlobPublicAccess: false
29-
networkAcls: {
30-
defaultAction: 'Deny'
31-
}
32-
}
3317
}
3418

3519
var storageBlobPrivateEndpointName = 'ccwstorage-blob-pe'

bicep/vm.bicep

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ param adminSshPublicKey string
1818
param vmSize string
1919
param dataDisks array
2020
param osDiskSize int = 0 //TODO: add to UI
21+
param managedIdentityId string
2122

2223
resource nic 'Microsoft.Network/networkInterfaces@2023-11-01' = {
2324
name: '${name}-nic'
@@ -39,7 +40,11 @@ resource nic 'Microsoft.Network/networkInterfaces@2023-11-01' = {
3940
}
4041
}
4142

42-
resource virtualMachine 'Microsoft.Compute/virtualMachines@2024-03-01' = {
43+
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
44+
name: split(managedIdentityId, '/')[8]
45+
}
46+
47+
resource virtualMachine 'Microsoft.Compute/virtualMachines@2024-11-01' = {
4348
name: name
4449
location: location
4550
tags: tags
@@ -49,7 +54,10 @@ resource virtualMachine 'Microsoft.Compute/virtualMachines@2024-03-01' = {
4954
name: split(image.plan,':')[2]
5055
} : null
5156
identity: {
52-
type: 'SystemAssigned'
57+
type: 'UserAssigned'
58+
userAssignedIdentities: {
59+
'${managedIdentityId}': {}
60+
}
5361
}
5462
properties: {
5563
hardwareProfile: {
@@ -132,6 +140,6 @@ resource cse 'Microsoft.Compute/virtualMachines/extensions@2024-03-01' = {
132140
output fqdn string = '' //contains(vm, 'pip') && vm.pip ? publicIp.properties.dnsSettings.fqdn : ''
133141
output publicIp string = '' //contains(vm, 'pip') && vm.pip ? publicIp.properties.ipAddress : ''
134142
output privateIp string = nic.properties.ipConfigurations[0].properties.privateIPAddress
135-
output principalId string = virtualMachine.identity.principalId
143+
output principalId string = managedIdentity.properties.principalId
136144
//output privateIps array = [ for i in range(0, count): nic[i].properties.ipConfigurations[0].properties.privateIPAddress ]
137145
//output principalIds array = [ for i in range(0, count): virtualMachine[i].identity.principalId ]

bicep/vmManagedIdentity.bicep

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
targetScope = 'resourceGroup'
22
import {tags_t} from './types.bicep'
33

4-
param name string
4+
param name string = 'ccwCycleCloudVirtualMachineManagedIdentity'
55
param location string
66
param applyRoleAssignments bool = true
77
param tags tags_t = {}
@@ -25,3 +25,5 @@ module ccwCycleCloudVirtualMachineRoleAssignments './vmManagedIdentityRoleAssign
2525
principalId: managedIdentity.properties.principalId
2626
}
2727
}
28+
29+
output managedIdentityId string = managedIdentity.id

util/ccw_prerequisites.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ fi
8585
az deployment group create \
8686
--resource-group "$RESOURCE_GROUP" \
8787
--template-file $(pwd)/bicep/vmManagedIdentity.bicep \
88-
--parameters name="ccwCycleCloudVirtualMachineManagedIdentity" \
8988
--parameters location="$LOCATION" \
9089
--parameters applyRoleAssignments="$APPLY_ROLE_ASSIGNMENTS" \
9190
--name "ccw-vm-mi-deployment-${RESOURCE_GROUP}-${LOCATION}"

0 commit comments

Comments
 (0)