【问题标题】:Create Table in Azure Storage Account在 Azure 存储帐户中创建表
【发布时间】:2016-07-17 17:14:15
【问题描述】:

有没有办法使用 ARM 模板在 Azure 存储帐户中创建表?我可以使用 PowerShell 实现这一点,但找不到使用 JSON 模板的方法,当我使用 (https://resources.azure.com) 浏览我的部署资源时,我看不到对存储帐户下创建的表的任何引用,任何知道为什么?

谢谢, 一个塞亚姆

【问题讨论】:

    标签: azure azure-resource-manager arm-template


    【解决方案1】:
    1. 据我所知,没有。详情可以查看Get started with Azure Table storage using .NET/PHP/Python/...
    2. 表服务通过 REST API 公开帐户、表、实体,因此您无法在门户中看到它们。您可以查看Addressing Table Service Resources 了解更多信息。

    【讨论】:

    • Steven 是正确的:#1 - 您不能在模板部署中执行数据平面操作以进行存储。 (即不能创建队列、容器、表等)
    • 其实可以创建一个容器。我还没有找到创建存储表的方法。 github.com/Azure/azure-quickstart-templates/blob/master/…
    • 这个答案已经过时了。 现在可以使用 ARM 模板和 Bicep 创建表。请参阅 Microsoft.Storage/storageAccounts/tableServices/tables@2021-06-01
    【解决方案2】:

    通过一些简单的步骤使用 ARM 模板创建 Azure 存储。请找到以下步骤来实现它。

    第 1 步:打开您的 powershell 并使用 Connect-AzureRmAccount 登录您的帐户

    第 2 步:添加您的 SubscriptionId Select-AzureRmSubscription -SubscriptionId <your SubscriptionId>

    第 3 步:创建资源组 New-AzureRmResourceGroup -Name yourResourceGroup -Location "South Central US"

    第 4 步:创建 azuredeploy.json 和 azuredeploy.parameters.json

    azuredeploy.json

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageAccountName": {
            "type": "string",
            "metadata": {
                "description": "The name of the Azure Storage account."
            }
        },
        "containerName": {
            "type": "string",
            "defaultValue": "logs",
            "metadata": {
                "description": "The name of the blob container."
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "The location in which the Azure Storage resources should be deployed."
            }
        }
    },
    "resources": [
        {
            "name": "[parameters('storageAccountName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2018-02-01",
            "location": "[parameters('location')]",
            "kind": "StorageV2",
            "sku": {
                "name": "Standard_LRS",
                "tier": "Standard"
            },
            "properties": {
                "accessTier": "Hot"
            },
            "resources": [
                {
                    "name": "[concat('default/', parameters('containerName'))]",
                    "type": "blobServices/containers",
                    "apiVersion": "2018-03-01-preview",
                    "dependsOn": [
                        "[parameters('storageAccountName')]"
                    ]
                }
            ]
        }
    ]
    }
    

    azuredeploy.parameters.json

    {
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageAccountName": {
            "value": "yourstorage"
        }
    }
    }
    

    第 5 步:运行以下命令

    New-AzureRmResourceGroupDeployment -Name myDeployment -ResourceGroupName yourResourceGroup -TemplateFile <location>\azuredeploy.json -TemplateParameterFile <location>\azuredeploy.parameters.json
    

    第 6 步:

    $saContext = (Get-AzureRmStorageAccount -ResourceGroupName yourResourceGroup -Name sitastoragee).Context 
    New-AzureStorageTable –Name yourtablestorage –Context $saContext
    

    【讨论】:

    • 这个示例是创建一个容器而不是一个表
    【解决方案3】:

    您可以像这样通过 ARM 创建一个带有表的 Azure 存储帐户,在您的 storageAccount 资源上使用 tableServices/tables 子资源:

    {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "storageAccountName": {
          "type": "string",
          "minLength": 3,
          "maxLength": 24
        },
        "storageAccountSku": {
          "type": "string",
          "defaultValue": "Standard_LRS",
          "allowedValues": [
            "Standard_LRS",
            "Standard_GRS",
            "Standard_RAGRS"
          ]
        },
        "tableName": {
          "type": "string",
          "minLength": 3,
          "maxLength": 63
        }
      },
      "resources": [
        {
          "type": "Microsoft.Storage/storageAccounts",
          "name": "[parameters('storageAccountName')]",
          "apiVersion": "2019-06-01",
          "location": "[resourceGroup().location]",
          "kind": "StorageV2",
          "sku": {
            "name": "[parameters('storageAccountSku')]"
          },
          "resources": [
            {
              "name": "[concat('default/', parameters('tableName'))]",
              "type": "tableServices/tables",
              "apiVersion": "2019-06-01",
              "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
              ]
            }
          ]
        }
      ]
    }
    

    该功能记录在ARM Template spec page for tableServices/tables

    【讨论】:

      猜你喜欢
      • 2017-11-23
      • 1970-01-01
      • 2014-06-17
      • 1970-01-01
      • 2017-03-13
      • 2017-01-24
      • 2018-02-09
      • 1970-01-01
      • 2020-04-29
      相关资源
      最近更新 更多