简体   繁体   English

如何强制Azure存储帐户作为经典

[英]How to force Azure Storage Account as classic

We recently built a infrastructure and application deployment framework using the Azure Resource Manager and templates. 我们最近使用Azure资源管理器和模板构建了基础架构和应用程序部署框架。 In order to deploy a Cloud Service, it is required to first setup an Azure Storage Account. 要部署Cloud Service,首先需要设置Azure存储帐户。 As of recently, this was accomplished by running: 截至最近,这是通过运行:

Switch-AzureMode AzureResourceManager

New-AzureStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $storageAccountName -Location $locationName -Type Standard_LRS

This would create a storage account that the New-AzureDeployment cmdlet could use for the deployment. 这将创建New-AzureDeployment cmdlet可用于部署的存储帐户。 As far as I can remember, the storage account created would be one that the now labeled as "classic" in the UI. 据我所知,创建的存储帐户将是现在在UI中标记为“经典”的存储帐户。 However, with recent changes, the storage account that is now created using the script above is non-classic (V2). 但是,对于最近的更改,现在使用上面的脚本创建的存储帐户是非经典的(V2)。 This V2 storage account is not recognized by the New-AzureDeployment, and it throws this in the Powershell script: New-AzureDeployment无法识别此V2存储帐户,并在Powershell脚本中将其抛出:

New-AzureDeployment : ResourceNotFound: The storage account 'teststorage' was not found. New-AzureDeployment:ResourceNotFound:找不到存储帐户“teststorage”。

If I manually create the classic storage account in the UI, I can use it for my deployment, and it works just fine. 如果我在UI中手动创建经典存储帐户,我可以将其用于我的部署,并且它可以正常工作。

So is it possible to do one of the following: 那么可以执行以下操作之一:

  1. Force the storage account to be created as classic via Powershell? 通过Powershell强制将存储帐户创建为经典帐户?
  2. Instruct the New-AzureDeployment cmdlet to use the V2 storage account via Powershell? 指示New-AzureDeployment cmdlet通过Powershell使用V2存储帐户?

切换回asm模式(v1 api)并从那里创建存储帐户:

switch-azuremode -Name AzureServiceManagement

You can actually use ARM (Azure Resource Manager) to create a "Classic" (ie old portal) storage account. 您实际上可以使用ARM(Azure资源管理器)来创建“经典”(即旧门户)存储帐户。 To do this, add the below json into your "Resources", adjusting the params as you require. 为此,将以下json添加到“资源”中,根据需要调整参数。 The advantage this has over @Trondh answer is that this will be provisioned as part of your resource group. 这比@Trondh回答的优势在于,它将作为资源组的一部分进行配置。 When you switch back to the ASM your classic storage account will just be added to a random resource group that you cannot move. 当您切换回ASM时,您的经典存储帐户将被添加到您无法移动的随机资源组中。

       {
            "name": "[concat(parameters('BuildStorageName'), 'classic')]",
            "type": "Microsoft.ClassicStorage/storageAccounts",
            "location": "[parameters('BuildStorageLocation')]",
            "apiVersion": "2015-06-01",
            "dependsOn": [ ],
            "properties": {
                "accountType": "[parameters('BuildStorageType')]"
            }
        }

Because someone else may find this helpful with the later versions of Azure resource manager (my version was 1.0.4).... 因为其他人可能会发现这对Azure资源管理器的更高版本有帮助(我的版本是1.0.4)....

In the latest versions of AzureRM for PSVersion 5.0.10514.6, this can be done through a powershell cmdlet. 在最新版本的AzureRM for PSVersion 5.0.10514.6中,可以通过powershell cmdlet完成此操作。

Assuming you have: 假设你有:

a) Authenticated to Azure RM: Login-AzureRMAccount a)对Azure RM进行身份验证: Login-AzureRMAccount

b) Already have created the resource group: New-AzureRmResourceGroup -Name $resourceGroupName -Location "South Central US" b)已经创建了资源组: New-AzureRmResourceGroup -Name $ resourceGroupName -Location“South Central US”

You can then do something like this to get a classic storage account: 然后,您可以执行以下操作来获取经典存储帐户:

New-AzureRmResource -ResourceName "" -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.ClassicStorage/StorageAccounts" -Location "South Central US" -Properties @{ AccountType = "Standard_LRS" } -ApiVersion "2015-06-01" New-AzureRmResource -ResourceName“” - ResourceGroupName $ resourceGroupName -ResourceType“Microsoft.ClassicStorage / StorageAccounts”-Location“South Central US”-Properties @ {AccountType =“Standard_LRS”} -ApiVersion“2015-06-01”

Jason's answer is definitively the best solution.. 杰森的答案绝对是最好的解决方案..

$resourceGroupName= "myrsgroupp"
$classicStorageName = "myclassicstoragename"
$location = "North Europe"
New-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceName $classicStorageName -ResourceType "Microsoft.ClassicStorage/StorageAccounts" -Location $location -Properties @{AccountType="Standard_LRS"} -ApiVersion "2015-06-01" -Force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM