在Azure存储账户中创建表格。

6
有没有一种方式可以使用ARM模板在Azure存储帐户内创建表格?我可以使用PowerShell实现,但无法找到使用JSON模板的方法。此外,当我使用(https://resources.azure.com)浏览我的部署资源时,我看不到在存储帐户下创建的表格的任何引用,有什么想法吗?
谢谢, A Seyam
3个回答

4
您可以通过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模板规范页面上进行了记录。 (链接)

3

史蒂文在#1方面是正确的 - 您无法执行数据平面操作以在模板部署中进行存储。 (即无法创建队列,容器,表等) - bmoore-msft
实际上,您可以创建一个容器。我还没有找到创建存储表的方法。https://github.com/Azure/azure-quickstart-templates/blob/master/101-storage-blob-container/azuredeploy.json - jayt.dev
此答案已经过时。现在可以使用ARM模板和Bicep创建表格。请参见Microsoft.Storage/storageAccounts/tableServices/tables@2021-06-01。 - bananabrann

-1

使用 ARM 模板创建 Azure 存储的简单步骤。请按以下步骤实施。

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

第 2 步:添加您的订阅 ID 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

1
此示例是创建一个容器而不是表格。 - Jorn.Beyers

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接