Azure / azure-quickstart-templates

Azure Quickstart Templates
https://aka.ms/azqst
MIT License
13.94k stars 16.07k forks source link

Cannot rerun front-door-standard-premium-storage-static-website template #12415

Open matthew-thomas opened 2 years ago

matthew-thomas commented 2 years ago

front-door-standard-premium-storage-static-website

Issue Details

First run of this template works successfully, subsequent runs fail making this template unusable in a continuous delivery pipeline.

After deploying this template first time, I'm able to see the "Welcome" text on the index page of the frontDoorEndpointHostName output. However, any subsequent runs of this main.bicep file fail if any changes have been made.

It is my understanding that Bicep/ARM templates are designed to be Desired State Configuration and expected to be used as such (run many times to apply updates). However, this template doesn't seem to work in this fashion. What am I missing?

Repro steps

  1. git clone https://github.com/Azure/azure-quickstart-templates.git
  2. Create a resource group named "cdn".
  3. az login
  4. front-door-standard-premium-storage-static-website> az deployment group create --resource-group cdn --template-file main.bicep
  5. Verify "Welcome" is viewable at the host that is shown in the output for frontDoorEndpointHostName from step 4.
  6. Modify scripts\enable-storage-static-website.ps1 Line 15 to say "Welcome!"
  7. Rerun command from Step 4, get the following error:

{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"Conflict","message":"{\r\n \"status\": \"Failed\",\r\n \"error\": {\r\n \"code\": \"ResourceDeploymentFailure\",\r\n \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.\",\r\n \"details\": [\r\n {\r\n \"code\": \"DeploymentFailed\",\r\n \"message\": \"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.\",\r\n \"details\": [\r\n {\r\n \"code\": \"Conflict\",\r\n \"message\": \"{\r\n \\"status\\": \\"failed\\",\r\n \\"error\\": {\r\n \\"code\\": \\"ResourceDeploymentFailure\\",\r\n \\"message\\": \\"The resource operation completed with terminal provisioning state 'failed'.\\",\r\n \\"details\\": [\r\n {\r\n \\"code\\": \\"DeploymentScriptError\\",\r\n \\"message\\": \\"The provided script failed with the following error:\\r\\nSystem.NullReferenceException: Object reference not set to an instance of an object.\\n at Microsoft.PowerShell.ConsoleHostUserInterface.PromptForChoice(String caption, String message, Collection1 choices, Int32 defaultChoice)\\\\n at System.Management.Automation.Internal.Host.InternalHostUserInterface.PromptForChoice(String caption, String message, Collection1 choices, Int32 defaultChoice)\\n at System.Management.Automation.MshCommandRuntime.InquireHelper(String inquireMessage, String inquireCaption, Boolean allowYesToAll, Boolean allowNoToAll, Boolean replaceNoWithHalt, Boolean hasSecurityImpact)\\n at System.Management.Automation.MshCommandRuntime.DoShouldContinue(String query, String caption, Boolean hasSecurityImpact, Boolean supportsToAllOptions, Boolean& yesToAll, Boolean& noToAll)\\n at System.Management.Automation.MshCommandRuntime.ShouldContinue(String query, String caption)\\n at System.Management.Automation.Cmdlet.ShouldContinue(String query, String caption)\\n at Microsoft.WindowsAzure.Commands.Storage.Blob.StorageDataMovementCmdletBase.b__21_1(String s1, String s2, String s3)\\n at Microsoft.WindowsAzure.Commands.Storage.Common.TaskOutputStream.ConfirmRequest(ConfirmTaskCompletionSource tcs)\\n--- End of stack trace from previous location where exception was thrown ---\\n at Microsoft.WindowsAzure.Commands.Storage.Blob.StorageDataMovementCmdletBase.ConfirmOverwriteAsync(Object source, Object destination)\\n at Microsoft.Azure.Storage.DataMovement.TransferControllers.TransferControllerBase.CheckOverwriteAsync(Boolean exist, Object source, Object dest)\\n at Microsoft.Azure.Storage.DataMovement.TransferControllers.BlockBlobWriter.HandleFetchAttributesResultAsync(Exception e)\\n at Microsoft.Azure.Storage.DataMovement.TransferControllers.BlockBlobWriter.FetchAttributesAsync()\\n at Microsoft.Azure.Storage.DataMovement.TransferControllers.BlockBlobWriter.DoWorkInternalAsync()\\n at Microsoft.Azure.Storage.DataMovement.TransferControllers.SyncTransferController.DoWorkInternalAsync()\\n at Microsoft.Azure.Storage.DataMovement.TransferControllers.TransferControllerBase.DoWorkAsync()\\n at Microsoft.Azure.Storage.DataMovement.TransferScheduler.ExecuteJobInternalAsync(TransferJob job, CancellationToken cancellationToken)\\n at Microsoft.Azure.Storage.DataMovement.SingleObjectTransfer.ExecuteAsync(TransferScheduler scheduler, CancellationToken cancellationToken)\\n at Microsoft.Azure.Storage.DataMovement.TransferManager.DoTransfer(Transfer transfer, TransferContext transferContext, CancellationToken cancellationToken)\\n at Microsoft.WindowsAzure.Commands.Storage.Common.DataMovementTransferHelper.DoTransfer(Func`1 doTransfer, ProgressRecord record, TaskOutputStream outputStream)\\n at Microsoft.WindowsAzure.Commands.Storage.Blob.SetAzureBlobContentCommand.Upload2Blob(Int64 taskId, IStorageBlobManagement localChannel, String filePath, CloudBlob blob)\\n at Microsoft.WindowsAzure.Commands.Storage.Common.LimitedConcurrencyTaskScheduler.RunConcurrentTask(Int64 taskId, Task task)\\r\\nat , /mnt/azscripts/azscriptinput/userscript.ps1: line 16\\r\\nat , : line 1\\r\\nat , /mnt/azscripts/azscriptinput/DeploymentScript.ps1: line 239. Please refer to https://aka.ms/DeploymentScriptsTroubleshoot for more deployment script information.\\"\r\n }\r\n ]\r\n }\r\n}\"\r\n }\r\n ]\r\n }\r\n ]\r\n }\r\n}"}]}}

matthew-thomas commented 2 years ago

Figured it out:

The System.NullReferenceException: Object reference not set to an instance of an object. error is due to Set-AzStorageBlobContent prompting for confirmation to overwrite the index.html file on the console.

Adding -Force flag to both of the Set-AzStorageBlobContent calls in the script resolves the issue and allows for updates to occur.