因此,现在(显然)可以通过ARM模板创建Blob容器,是否可以类似地创建Azure存储表?我进行了搜索,但是大多数答案来自Blob容器创建的实施和可用之前。
我还在https://docs.microsoft.com/en-us/rest/api/storageservices/create-table上找到了REST API的文档,但是我不确定这是否以及如何映射到ARM模板中的JSON条目。
我希望消除当前在部署中处理Table资源创建的PowerShell脚本。
答案 0 :(得分:3)
从2019年6月1日开始可以创建表服务和表。
餐桌服务
{
"name": "default",
"type": "Microsoft.Storage/storageAccounts/tableServices",
"apiVersion": "2019-06-01",
"properties": {
"cors": {
"corsRules": [
{
"allowedOrigins": [
"string"
],
"allowedMethods": [
"string"
],
"maxAgeInSeconds": "integer",
"exposedHeaders": [
"string"
],
"allowedHeaders": [
"string"
]
}
]
}
},
"resources": []
}
表格
{
"name": "string",
"type": "Microsoft.Storage/storageAccounts/tableServices/tables",
"apiVersion": "2019-06-01"
}
答案 1 :(得分:2)
否,目前无法通过ARM模板执行此操作。
答案 2 :(得分:2)
我想为将来尝试安装带有表服务的ARM模板的任何人提供一个答案,因为当前文档似乎对如何实现它们非常含糊。特别注意名称的格式,并且所有项目均定义为根级资源:
{
"name": "[concat(parameters('storageAccount_name'),'/', parameters('tableServiceName'))]",
"type": "Microsoft.Storage/storageAccounts/tableServices",
"apiVersion": "2019-06-01",
"properties": {
"cors": {
"corsRules": [
{
"allowedOrigins": [
"*"
],
"allowedMethods": [
"PUT",
"GET",
"POST"
],
"maxAgeInSeconds": 0,
"exposedHeaders": [
"*"
],
"allowedHeaders": [
"*"
]
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccount_name'))]"
],
"resources": []
},
{
"name": "[concat(parameters('storageAccount_name'),'/default/',parameters('table_name'))]",
"type": "Microsoft.Storage/storageAccounts/tableServices/tables",
"apiVersion": "2019-06-01",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/tableServices', parameters('storageAccount_name'), 'default')]",
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccount_name'))]"
]
}
答案 3 :(得分:0)
示例 ARM 模板以在存储帐户中创建 Blob 和表
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string",
"metadata": {
"description": "Specifies the name of the Azure Storage account."
}
},
"containerName": {
"type": "string",
"defaultValue": "logs",
"metadata": {
"description": "Specifies the name of the blob container."
}
},
"tableName": {
"type": "string",
"defaultValue": "logstable",
"metadata": {
"description": "Specifies the name of the table."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specifies the location in which the Azure Storage resources should be deployed."
}
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-06-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_GRS",
"tier": "Standard"
},
"kind": "StorageV2",
"properties": {
"accessTier": "Hot",
"minimumTlsVersion": "TLS1_2",
"allowBlobPublicAccess": false,
"supportsHttpsTrafficOnly": true
},
"resources": [
{
"type": "blobServices/containers",
"apiVersion": "2019-06-01",
"name": "[concat('default/', parameters('containerName'))]",
"dependsOn": [
"[parameters('storageAccountName')]"
]
},
{
"type": "tableServices/tables",
"apiVersion": "2019-06-01",
"name": "[concat('default/', parameters('tableName'))]",
"dependsOn": [
"[parameters('storageAccountName')]"
]
}
]
}
]
}
答案 4 :(得分:0)
您可以在代码中使用 CreateIfNotExistsAsync 方法