在Azure存储帐户中创建表

时间:2016-03-29 22:35:48

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

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

谢谢, 一个Seyam

3 个答案:

答案 0 :(得分:3)

  1. 据我所知,没有。您可以查看Get started with Azure Table storage using .NET/PHP/Python/...了解详细信息。
  2. Table服务通过REST API公开Account,Tables,Entity,因此您无法在门户中看到它们。您可以查看Addressing Table Service Resources了解详情。

答案 1 :(得分:1)

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

{
  "$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上。

答案 2 :(得分:0)

使用一些简单的步骤即可使用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