Skip to content

Commit

Permalink
Merge branch '24-error-when-deploying-via-the-ui' into resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
WillyMoselhy authored Nov 8, 2024
2 parents 6fadbd9 + 7c9d2b6 commit 638a634
Show file tree
Hide file tree
Showing 11 changed files with 414 additions and 275 deletions.
3 changes: 2 additions & 1 deletion FunctionApp/TimerTrigger1/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ $runningDeployments = Get-SHRRunningDeployment -ResourceGroupName $sessionHostRe
Write-PSFMessage -Level Host -Message "Found {0} running deployments" -StringValues $runningDeployments.Count

# load session host parameters
$sessionHostParameters = (Get-FunctionConfig _SessionHostParameters)
$sessionHostParameters = [hashtable]::new([System.StringComparer]::InvariantCultureIgnoreCase)
$sessionHostParameters += (Get-FunctionConfig _SessionHostParameters)

# Get latest version of session host image
Write-PSFMessage -Level Host -Message "Getting latest image version using Image Reference: {0}" -StringValues ($sessionHostParameters.ImageReference | Out-String)
Expand Down
3 changes: 2 additions & 1 deletion FunctionApp/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Set-PSFConfig -FullName PSFramework.Message.style.NoColor -Value $true #This is

## Version Banner ## Updated by Build\Build-Zip-File.ps1

Write-PSFMessage -Level Host -Message "This is SessionHostReplacer version {0}" -StringValues 'v0.3.1'

Write-PSFMessage -Level Host -Message "This is SessionHostReplacer version {0}" -StringValues 'v0.3.1-beta.5'


# Import Function Parameters
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ the AVD Session Host Replacer helps you manage the task of replacing old session

| Deployment Type | Link |
| :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Azure Portal UI | [![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#blade/Microsoft_Azure_CreateUIDef/CustomDeploymentBlade/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1%2Fdeploy%2Farm%2FDeployAVDSessionHostReplacer.json/uiFormDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1%2Fdeploy%2Fportal-ui%2Fportal-ui.json) [![Deploy to Azure Gov](https://aka.ms/deploytoazuregovbutton)](https://portal.azure.us/#blade/Microsoft_Azure_CreateUIDef/CustomDeploymentBlade/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1%2Fdeploy%2Farm%2FDeployAVDSessionHostReplacer.json/uiFormDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1%2Fdeploy%2Fportal-ui%2Fportal-ui.json) [![Deploy to Azure China](https://aka.ms/deploytoazurechinabutton)](https://portal.azure.cn/#blade/Microsoft_Azure_CreateUIDef/CustomDeploymentBlade/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1%2Fdeploy%2Farm%2FDeployAVDSessionHostReplacer.json/uiFormDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1%2Fdeploy%2Fportal-ui%2Fportal-ui.json) |
| Azure Portal UI | [![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#blade/Microsoft_Azure_CreateUIDef/CustomDeploymentBlade/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1-beta.5%2Fdeploy%2Farm%2FDeployAVDSessionHostReplacer.json/uiFormDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1-beta.5%2Fdeploy%2Fportal-ui%2Fportal-ui.json) [![Deploy to Azure Gov](https://aka.ms/deploytoazuregovbutton)](https://portal.azure.us/#blade/Microsoft_Azure_CreateUIDef/CustomDeploymentBlade/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1-beta.5%2Fdeploy%2Farm%2FDeployAVDSessionHostReplacer.json/uiFormDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1-beta.5%2Fdeploy%2Fportal-ui%2Fportal-ui.json) [![Deploy to Azure China](https://aka.ms/deploytoazurechinabutton)](https://portal.azure.cn/#blade/Microsoft_Azure_CreateUIDef/CustomDeploymentBlade/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1-beta.5%2Fdeploy%2Farm%2FDeployAVDSessionHostReplacer.json/uiFormDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2FAVDSessionHostReplacer%2Fv0.3.1-beta.5%2Fdeploy%2Fportal-ui%2Fportal-ui.json) |
| Command line (Bicep/ARM) | [![Powershell/Azure CLI](./docs/icons/powershell.png)](./docs/CodeDeploy.md)
| Offline Deployment | [![Offline Deployment](./docs/icons/powershell.png)](./docs/CodeDeploy-offline.md) |

Expand Down
3 changes: 3 additions & 0 deletions StandardSessionHostTemplate/DeploySessionHosts.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
param Location string = resourceGroup().location
param AvailabilityZones array = []
param VMNames array
param VMNamePrefixLength int

param VMSize string

param SubnetID string
Expand Down Expand Up @@ -41,6 +43,7 @@ module deploySessionHosts 'modules/AVDStandardSessionHost.bicep' = [for vm in VM
SecurityProfile: SecurityProfile
SubnetID: SubnetID
VMName: vm
VMNamePrefixLength: VMNamePrefixLength
VMSize: VMSize
DiskType: DiskType
WVDArtifactsURL: WVDArtifactsURL
Expand Down
11 changes: 10 additions & 1 deletion StandardSessionHostTemplate/DeploySessionHosts.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"VMNames": {
"type": "array"
},
"VMNamePrefixLength": {
"type": "int"
},
"VMSize": {
"type": "string"
},
Expand Down Expand Up @@ -104,6 +107,9 @@
"VMName": {
"value": "[parameters('VMNames')[copyIndex()]]"
},
"VMNamePrefixLength": {
"value": "[parameters('VMNamePrefixLength')]"
},
"VMSize": {
"value": "[parameters('VMSize')]"
},
Expand Down Expand Up @@ -143,6 +149,9 @@
"VMName": {
"type": "string"
},
"VMNamePrefixLength": {
"type": "int"
},
"VMSize": {
"type": "string"
},
Expand Down Expand Up @@ -200,7 +209,7 @@
},
"variables": {
"varRequireNvidiaGPU": "[or(startsWith(parameters('VMSize'), 'Standard_NC'), contains(parameters('VMSize'), '_A10_v5'))]",
"varVMNumber": "[int(substring(parameters('VMName'), add(lastIndexOf(parameters('VMName'), '-'), 1), sub(sub(length(parameters('VMName')), lastIndexOf(parameters('VMName'), '-')), 1)))]",
"varVMNumber": "[int(substring(parameters('VMName'), parameters('VMNamePrefixLength'), sub(length(parameters('VMName')), parameters('VMNamePrefixLength'))))]",
"varAvailabilityZone": "[if(equals(parameters('AvailabilityZones'), createArray()), createArray(), createArray(format('{0}', parameters('AvailabilityZones')[mod(variables('varVMNumber'), length(parameters('AvailabilityZones')))])))]"
},
"resources": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This is a sample bicep file //

param VMName string
param VMNamePrefixLength int
param VMSize string
param DiskType string
param Location string = resourceGroup().location
Expand Down Expand Up @@ -36,8 +37,8 @@ var varRequireNvidiaGPU = startsWith(VMSize, 'Standard_NC') || contains(VMSize,
var varVMNumber = int(
substring(
VMName,
(lastIndexOf(VMName, '-') + 1),
(length(VMName) - lastIndexOf(VMName, '-') - 1)
VMNamePrefixLength,
(length(VMName) - VMNamePrefixLength)
)
)

Expand Down
63 changes: 45 additions & 18 deletions deploy/arm/DeployAVDSessionHostReplacer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@
"description": "Required: Yes | Name of the Log Analytics Workspace used by the Function App Insights."
}
},
"UseStandardTemplate": {
"type": "bool",
"defaultValue": true
},
"SessionHostsRegion": {
"type": "string"
"type": "string",
"defaultValue": ""
},
"AvailabilityZones": {
"type": "array",
"defaultValue": []
},
"SessionHostSize": {
"type": "string"
"type": "string",
"defaultValue": ""
},
"AcceleratedNetworking": {
"type": "bool"
"type": "bool",
"defaultValue": false
},
"SessionHostDiskType": {
"type": "string",
Expand All @@ -69,6 +76,7 @@
},
"MarketPlaceOrCustomImage": {
"type": "string",
"defaultValue": "Marketplace",
"allowedValues": [
"Marketplace",
"Gallery"
Expand Down Expand Up @@ -116,10 +124,12 @@
"defaultValue": true
},
"SubnetId": {
"type": "string"
"type": "string",
"defaultValue": ""
},
"IdentityServiceProvider": {
"type": "string",
"defaultValue": "EntraID",
"allowedValues": [
"EntraID",
"ActiveDirectory",
Expand Down Expand Up @@ -147,7 +157,23 @@
"defaultValue": ""
},
"LocalAdminUsername": {
"type": "string"
"type": "string",
"defaultValue": ""
},
"CustomTemplateSpecResourceId": {
"type": "string",
"defaultValue": ""
},
"VMNamesTemplateParameterName": {
"type": "string",
"defaultValue": "VMNames",
"metadata": {
"description": "Required: No | The name of the parameter in the template that specifies the VM Names array."
}
},
"CustomTemplateSpecParameters": {
"type": "string",
"defaultValue": "{}"
},
"HostPoolResourceGroupName": {
"type": "string",
Expand Down Expand Up @@ -293,13 +319,6 @@
"description": "Required: No | Delay in days before replacing session hosts when a new image version is detected. | Default: 0 (no delay)."
}
},
"VMNamesTemplateParameterName": {
"type": "string",
"defaultValue": "VMNames",
"metadata": {
"description": "Required: No | The name of the parameter in the template that specifies the VM Names array."
}
},
"SessionHostResourceGroupName": {
"type": "string",
"defaultValue": "",
Expand Down Expand Up @@ -463,7 +482,7 @@
},
{
"name": "_SessionHostParameters",
"value": "[string(createObject('Location', parameters('SessionHostsRegion'), 'AvailabilityZones', parameters('AvailabilityZones'), 'VMSize', parameters('SessionHostSize'), 'AcceleratedNetworking', parameters('AcceleratedNetworking'), 'DiskType', parameters('SessionHostDiskType'), 'ImageReference', variables('varImageReference'), 'SecurityProfile', variables('varSecurityProfile'), 'SubnetId', parameters('SubnetId'), 'DomainJoinObject', variables('varDomainJoinObject'), 'DomainJoinPassword', if(equals(parameters('IdentityServiceProvider'), 'EntraID'), null(), createObject('reference', createObject('keyVault', createObject('id', reference(resourceId('Microsoft.Resources/deployments', 'deployKeyVault'), '2022-09-01').outputs.keyVaultId.value), 'secretName', 'DomainJoinPassword'))), 'AdminUsername', parameters('LocalAdminUsername'), 'tags', createObject()))]"
"value": "[string(if(parameters('UseStandardTemplate'), createObject('Location', parameters('SessionHostsRegion'), 'AvailabilityZones', parameters('AvailabilityZones'), 'VMSize', parameters('SessionHostSize'), 'AcceleratedNetworking', parameters('AcceleratedNetworking'), 'DiskType', parameters('SessionHostDiskType'), 'ImageReference', variables('varImageReference'), 'SecurityProfile', variables('varSecurityProfile'), 'SubnetId', parameters('SubnetId'), 'DomainJoinObject', variables('varDomainJoinObject'), 'DomainJoinPassword', if(equals(parameters('IdentityServiceProvider'), 'EntraID'), null(), createObject('reference', createObject('keyVault', createObject('id', reference(resourceId('Microsoft.Resources/deployments', 'deployKeyVault'), '2022-09-01').outputs.keyVaultId.value), 'secretName', 'DomainJoinPassword'))), 'AdminUsername', parameters('LocalAdminUsername'), 'VMNamePrefixLength', add(length(parameters('SessionHostNamePrefix')), length(parameters('SessionHostNameSeparator'))), 'tags', createObject()), parameters('CustomTemplateSpecParameters')))]"
},
{
"name": "_SubscriptionId",
Expand All @@ -479,11 +498,11 @@
},
{
"name": "_ClientId",
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', split(parameters('UserAssignedManagedIdentityResourceId'), '/')[2], split(parameters('UserAssignedManagedIdentityResourceId'), '/')[4]), 'Microsoft.ManagedIdentity/userAssignedIdentities', split(parameters('UserAssignedManagedIdentityResourceId'), '/')[8]), '2023-01-31').clientId]"
"value": "[if(parameters('UseUserAssignedManagedIdentity'), reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', split(parameters('UserAssignedManagedIdentityResourceId'), '/')[2], split(parameters('UserAssignedManagedIdentityResourceId'), '/')[4]), 'Microsoft.ManagedIdentity/userAssignedIdentities', split(parameters('UserAssignedManagedIdentityResourceId'), '/')[8]), '2023-01-31').clientId, '')]"
},
{
"name": "_TenantId",
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', split(parameters('UserAssignedManagedIdentityResourceId'), '/')[2], split(parameters('UserAssignedManagedIdentityResourceId'), '/')[4]), 'Microsoft.ManagedIdentity/userAssignedIdentities', split(parameters('UserAssignedManagedIdentityResourceId'), '/')[8]), '2023-01-31').tenantId]"
"value": "[if(parameters('UseUserAssignedManagedIdentity'), reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', split(parameters('UserAssignedManagedIdentityResourceId'), '/')[2], split(parameters('UserAssignedManagedIdentityResourceId'), '/')[4]), 'Microsoft.ManagedIdentity/userAssignedIdentities', split(parameters('UserAssignedManagedIdentityResourceId'), '/')[8]), '2023-01-31').tenantId, '')]"
},
{
"name": "_GraphEnvironmentName",
Expand Down Expand Up @@ -716,8 +735,7 @@
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('varAppServicePlanName'))]",
"siteConfig": {
"use32BitWorkerProcess": false,
"powerShellVersion": "7.2",
"netFrameworkVersion": "v6.0",
"powerShellVersion": "7.4",
"appSettings": "[union(createArray(createObject('name', 'FUNCTIONS_EXTENSION_VERSION', 'value', '~4'), createObject('name', 'FUNCTIONS_WORKER_RUNTIME', 'value', 'powershell'), createObject('name', 'AzureWebJobsStorage', 'value', format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', variables('varStorageAccountName'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('varStorageAccountName')), '2022-05-01').keys[0].value)), createObject('name', 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING', 'value', format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', variables('varStorageAccountName'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('varStorageAccountName')), '2022-05-01').keys[0].value)), createObject('name', 'APPINSIGHTS_INSTRUMENTATIONKEY', 'value', reference(resourceId('Microsoft.Insights/components', variables('varAppServicePlanName')), '2020-02-02').InstrumentationKey), createObject('name', 'WEBSITE_CONTENTSHARE', 'value', toLower(parameters('FunctionAppName')))), if(parameters('EnableMonitoring'), createArray(createObject('name', 'APPINSIGHTS_INSTRUMENTATIONKEY', 'value', reference(resourceId('Microsoft.Insights/components', variables('varAppServicePlanName')), '2020-02-02').InstrumentationKey)), createArray()), parameters('ReplacementPlanSettings'))]",
"ftpsState": "Disabled",
"cors": {
Expand Down Expand Up @@ -886,6 +904,9 @@
"VMNames": {
"type": "array"
},
"VMNamePrefixLength": {
"type": "int"
},
"VMSize": {
"type": "string"
},
Expand Down Expand Up @@ -970,6 +991,9 @@
"VMName": {
"value": "[[parameters('VMNames')[copyIndex()]]"
},
"VMNamePrefixLength": {
"value": "[[parameters('VMNamePrefixLength')]"
},
"VMSize": {
"value": "[[parameters('VMSize')]"
},
Expand Down Expand Up @@ -1009,6 +1033,9 @@
"VMName": {
"type": "string"
},
"VMNamePrefixLength": {
"type": "int"
},
"VMSize": {
"type": "string"
},
Expand Down Expand Up @@ -1066,7 +1093,7 @@
},
"variables": {
"varRequireNvidiaGPU": "[[or(startsWith(parameters('VMSize'), 'Standard_NC'), contains(parameters('VMSize'), '_A10_v5'))]",
"varVMNumber": "[[int(substring(parameters('VMName'), add(lastIndexOf(parameters('VMName'), '-'), 1), sub(sub(length(parameters('VMName')), lastIndexOf(parameters('VMName'), '-')), 1)))]",
"varVMNumber": "[[int(substring(parameters('VMName'), parameters('VMNamePrefixLength'), sub(length(parameters('VMName')), parameters('VMNamePrefixLength'))))]",
"varAvailabilityZone": "[[if(equals(parameters('AvailabilityZones'), createArray()), createArray(), createArray(format('{0}', parameters('AvailabilityZones')[mod(variables('varVMNumber'), length(parameters('AvailabilityZones')))])))]"
},
"resources": [
Expand Down
Loading

0 comments on commit 638a634

Please sign in to comment.