Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
danycontre committed Aug 2, 2023
1 parent 0b5b36f commit d6ac6e4
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
4 changes: 4 additions & 0 deletions workload/bicep/deploy-baseline.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ var varFslogixSharePath = '\\\\${varFslogixStorageName}.file.${environment().suf
var varBaseScriptUri = 'https://raw.githubusercontent.com/Azure/avdaccelerator/main/workload/'
var varFslogixScriptUri = (avdIdentityServiceProvider == 'AAD') ? '${varBaseScriptUri}scripts/Set-FSLogixRegKeysAAD.ps1' : '${varBaseScriptUri}scripts/Set-FSLogixRegKeys.ps1'
var varFsLogixScript = (avdIdentityServiceProvider == 'AAD') ? './Set-FSLogixRegKeysAad.ps1' : './Set-FSLogixRegKeys.ps1'
var varCompRgDeploCleanScript = './cleanUpRgDeployments.ps1'
var varCompRgDeploCleanScriptUri = '${varBaseScriptUri}scripts/cleanUpRgDeployments.ps1'
var varAvdAgentPackageLocation = 'https://wvdportalstorageblob.blob.${environment().suffixes.storage}/galleryartifacts/Configuration_09-08-2022.zip'
var varDiskEncryptionKeyExpirationInEpoch = dateTimeToEpoch(dateTimeAdd(time, 'P${string(diskEncryptionKeyExpirationInDays)}D'))
var varCreateStorageDeployment = (createAvdFslogixDeployment || createMsixDeployment == true) ? true : false
Expand Down Expand Up @@ -1271,6 +1273,8 @@ module sessionHosts './modules/avdSessionHosts/deploy.bicep' = [for i in range(1
fslogixScriptUri: varFslogixScriptUri
fslogixSharePath: '\\\\${varFslogixStorageName}.file.${environment().suffixes.storage}\\${varFslogixFileShareName}'
fsLogixScriptArguments: varFsLogixScriptArguments
compRgDeploCleanScript: varCompRgDeploCleanScript
compRgDeploCleanScriptUri: varCompRgDeploCleanScriptUri
marketPlaceGalleryWindows: varMarketPlaceGalleryWindows[avdOsImage]
useSharedImage: useSharedImage
tags: createResourceTags ? union(varCustomResourceTags, varAvdDefaultTags) : varAvdDefaultTags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ param fslogixSharePath string
@sys.description('URI for FSlogix configuration script.')
param fslogixScriptUri string

@sys.description('URI for compute RG deployment cleanup configuration script.')
param compRgDeploCleanScriptUri string

@sys.description('URI for compute RG deployment cleanup configuration script.')
param compRgDeploCleanScript string

@sys.description('Tags to be applied to resources')
param tags object

Expand Down Expand Up @@ -425,3 +431,21 @@ module addAvdHostsToHostPool './registerSessionHostsOnHopstPool.bicep' = [for i
]
}]

// Clean up depployment on compute objects RG
module computeRgDeploymentCleanUp './cleanUpRgDeployments.bicep' = {
scope: resourceGroup('${subscriptionId}', '${computeObjectsRgName}')
name: 'Fsl-Conf-${sessionHostBatchId}-1-${time}'
params: {
location: sessionHostLocation
name: '${sessionHostNamePrefix}${padLeft((1 + sessionHostCountIndex), 4, '0')}'
file: compRgDeploCleanScript
cleanUpScriptArguments: '-subscriptionId ${subscriptionId} -resourceGroupName ${computeObjectsRgName}'
baseScriptUri: compRgDeploCleanScriptUri
}
dependsOn: [
sessionHosts
sessionHostsMonitoringWait
addAvdHostsToHostPool
configureFsLogixAvdHosts
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ========== //
// Parameters //
// ========== //

@sys.description('Extension deployment name.')
param name string

@sys.description('Location where to deploy compute services.')
param location string

@sys.description('URI for clean up configuration script.')
param baseScriptUri string

@sys.description('Clean up script file name.')
param file string

@sys.description('Configuration arguments for clean up script.')
param cleanUpScriptArguments string

// =========== //
// Deployments //
// =========== //

// Clean up RG deployments.
resource fslogixConfigure 'Microsoft.Compute/virtualMachines/extensions@2022-08-01' = {
name: '${name}/DeploymentCleanUp'
location: location
properties: {
publisher: 'Microsoft.Compute'
type: 'CustomScriptExtension'
typeHandlerVersion: '1.10'
autoUpgradeMinorVersion: true
settings: {}
protectedSettings: {
fileUris: array(baseScriptUri)
commandToExecute: 'powershell -ExecutionPolicy Unrestricted -File ${file} ${cleanUpScriptArguments}'
}
}
}


8 changes: 8 additions & 0 deletions workload/bicep/modules/avdSessionHosts/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ param fslogixSharePath string
@sys.description('URI for FSlogix configuration script.')
param fslogixScriptUri string

@sys.description('URI for compute RG deployment cleanup configuration script.')
param compRgDeploCleanScriptUri string

@sys.description('URI for compute RG deployment cleanup configuration script.')
param compRgDeploCleanScript string

@sys.description('Tags to be applied to resources')
param tags object

Expand Down Expand Up @@ -199,6 +205,8 @@ module sessionHosts './.bicep/avdSessionHosts.bicep' = [for i in range(1, varSes
fsLogixScriptArguments: fsLogixScriptArguments
fslogixSharePath: fslogixSharePath
fslogixScriptUri: fslogixScriptUri
compRgDeploCleanScriptUri: compRgDeploCleanScriptUri
compRgDeploCleanScript: compRgDeploCleanScript
hostPoolToken: getHostPool.properties.registrationInfo.token
marketPlaceGalleryWindows: marketPlaceGalleryWindows
useSharedImage: useSharedImage
Expand Down
28 changes: 28 additions & 0 deletions workload/scripts/cleanUpRgDeployments.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
##############################################################
# Clean up resource group deployments
##############################################################

[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory)]
[string]$subscriptionId,

[Parameter(Mandatory)]
[string]$resourceGroupName
)

$ErrorActionPreference = 'Stop'

# Select subscription
Write-Output "Selecting subscription Subscription $subscriptionId."
Select-AzSubscription -subscriptionid $subscriptionId

# Get resource group succeeded deployments
Write-Output "Getting $resourceGroupName succeeded deployments"
$resourceGroupDeployments = Get-AzResourceGroupDeployment -ResourceGroupName rg-avd-m002-dev-usw3-pool-compute | Where-Object ProvisioningState -EQ 'Succeeded'

# Delete resource group deployments
Write-Output "Deleting succeded deployments on $resourceGroupName"
foreach ($resourceGroupDeployment in $resourceGroupDeployments) {
Remove-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name $resourceGroupDeployment.DeploymentName
}

0 comments on commit d6ac6e4

Please sign in to comment.