I'm migrating from cloud services classic to cloud services extended support and I'm also moving to deploy with a mixture of yml and powershell.
The documentation text mentions around using New-AzureCloudService for creating and updating the service but when I try to call it for the update I get an error saying the cloud service already exists hence why I've tried to get the cloud service first and if found, update they values but I can't seem to update the definition file as no property exists.
Here is the snippet of code I'm using
$cloudService = Get-AzCloudService -ResourceGroupName $resourceGroupName -CloudServiceName $name -ErrorAction SilentlyContinue
if ($cloudService) {
$cloudService.packageUrl = $cspkgUrl
$cloudService.Configuration = Get-Content "$buildDirectory/ServiceConfiguration.Dev.cscfg"
$cloudService | Update-AzCloudService
} else {
New-AzCloudService `
-Name $name `
-ResourceGroupName $resourceGroupName `
-Location "$location" `
-ConfigurationFile "$buildDirectory/ServiceConfiguration*.cscfg" `
-DefinitionFile "$buildDirectory/ServiceDefinition.csdef" `
-packageUrl $cspkgUrl
}
I'm using Az v11.1.0 and Az.CloudService v2.0.0
I'm expecting to be able to set the definition file path or url when updating the cloud service but I can't seem to workout how.
Slightly unrelated but the cloud service is triggered via a service bus so I could delete the cloud service and redeploy the entire service but I feel this is overcomplicating it and I should just be able to update the csdef.
How do I update .csdef for Azure Cloud Service (Extended Support) when deploying via PowerShell: -
After a workaround on your requirement, the solution I found is you have to modify the .csdef
or .csdef
files manually and then point it to the updated package file with the Update-AzCloudService
command. It means that you can only modify the packageurl
as you already did in your code. There is no possibility of modifying the .csdef
or .cscfg
files directly with the Update-AzCloudService
command.
As mentioned above, I modified .csdef
file and uploaded it to the storage account. Once it's done, I was obtaining the updated package URL from storage account as shown below.
$StartTime = Get-Date
$EndTime = $tokenStartTime.AddYears(2)
$acccontext = Get-AzStorageAccount -ResourceGroupName xx -Name xxx
$blob = Get-AzStorageBlob -Container xxx -Blob xxx.cspkg -Context $acccontext.Context
$Token = New-AzStorageBlobSASToken -Container xxx -Blob xx.cspkg -Permission rwd -StartTime $StartTime -ExpiryTime $EndTime -Context $acccontext.Context
$Url = $blob.ICloudBlob.Uri.AbsoluteUri + $Token
Note: After retrieving the URL in the above given manner, use your existed code to update the cloud service.
Refer MSDoc for better understanding on create/update a cloud service with PowerShell.