0
votes

I am using below pattern to create a container by passing variables using powershell, however there seems to be some issue with the context being created, which is not allowing me to create the container and is showing 404(the specified resource does not exist).

$storage= New-AzStorageAccount -ResourceGroupName $RESOURCE_GROUP_NAME -Location $LOCATION -Name $TF_STATE_STORAGE_ACCOUNT_NAME -SkuName Standard_LRS

$ctx=$storage.Context

New-AzStorageContainer -Name $TF_STATE_CONTAINER_NAME -Context $ctx

enter image description here

Note:(When i retried using the same command multiple times ,it showed me the same error and after around 10 minutes, my container got created, so maybe i am missing something regarding the context being created ??)

I have posted(link below as well) a question over the different context's being showed as referencing the LazyStorage Constructor of the namespace Microsoft.WindowsAzure.Commands.Common.Storage, however the cmdlet New-AzStorageContainer accepts type "Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext" as interface which should be fetching the AzureStorageContext Class not LazyAzureStorageContext Class.

https://docs.microsoft.com/en-us/powershell/module/az.storage/new-azstoragecontainer?view=azps-5.5.0

Question posted link :

https://docs.microsoft.com/en-us/answers/questions/289096/new-azstoragecontainer-command-not-accepting-valid.html?childToView=290003#comment-290003

Note: i have tried putting in Wait-Events as well between all the commands in the ps script, however of no use.

Note: i have tried using the commands with Azure CLI in powershell from azure portal's console and facing similar kind of issue with below error.

enter image description here

1

1 Answers

1
votes

Storage accounts are created asynchronously when you request them, as you've noted, so the issue seems to be related to waiting for the account. Perhaps instead of using the a script, you could deploy the storage account with an ARM template which includes both the account and the containers?

Another option could be using the REST API to create the storage account, and monitoring the 'provisioningState' of the account until it is 'Succeeded', before proceeding with the container request?

https://docs.microsoft.com/en-us/rest/api/storagerp/storage-sample-create-account