通过 Azure 资源管理器模板部署 Azure Table
Deploy Azure Table via Azure Resource Manager Template
现在(显然)可以通过 ARM 模板创建 Blob 容器,是否可以类似地创建 Azure 存储 Table?我四处搜索,但大多数答案都来自于 Blob 容器创建实现和可用之前。
我还在 https://docs.microsoft.com/en-us/rest/api/storageservices/create-table 找到了 REST API 的文档,但我不确定它是否以及如何映射到 ARM 模板中的 JSON 条目。
我希望删除当前在我的部署中处理 Table 资源创建的 PowerShell 脚本。
截至 2019-06-01 版本...是
不,目前无法使用 ARM 模板执行此操作。
https://docs.microsoft.com/en-us/rest/api/storagerp/table/create
https://docs.microsoft.com/en-us/azure/templates/microsoft.storage/2019-06-01/storageaccounts/tableservices
{
"name": "default",
"type": "Microsoft.Storage/storageAccounts/tableServices",
"apiVersion": "2019-06-01",
"properties": {
"cors": {
"corsRules": [
{
"allowedOrigins": [
"string"
],
"allowedMethods": [
"string"
],
"maxAgeInSeconds": "integer",
"exposedHeaders": [
"string"
],
"allowedHeaders": [
"string"
]
}
]
}
}
}
和表格:
{
"name": "string",
"type": "Microsoft.Storage/storageAccounts/tableServices/tables",
"apiVersion": "2019-06-01"
}
目前只有容器可用。 Microsoft 正在开发表格。
从 2019-06-01 开始可以创建 Table 服务和 Tables。
Table 服务
{
"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": []
}
Tables
{
"name": "string",
"type": "Microsoft.Storage/storageAccounts/tableServices/tables",
"apiVersion": "2019-06-01"
}
我想通过一个答案来更新此内容,以便将来尝试使用 table 服务设置 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'))]"
]
}
用于在存储帐户中创建 Blob 和 Table 的示例 ARM 模板
{
"$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')]"
]
}
]
}
]
}
您可以在代码中使用 CreateIfNotExistsAsync 方法
如果您的 azure storage table 尚不存在,它将创建它。所以你不必在 ARM 模板中添加东西。
现在(显然)可以通过 ARM 模板创建 Blob 容器,是否可以类似地创建 Azure 存储 Table?我四处搜索,但大多数答案都来自于 Blob 容器创建实现和可用之前。
我还在 https://docs.microsoft.com/en-us/rest/api/storageservices/create-table 找到了 REST API 的文档,但我不确定它是否以及如何映射到 ARM 模板中的 JSON 条目。
我希望删除当前在我的部署中处理 Table 资源创建的 PowerShell 脚本。
截至 2019-06-01 版本...是
不,目前无法使用 ARM 模板执行此操作。
https://docs.microsoft.com/en-us/rest/api/storagerp/table/create
https://docs.microsoft.com/en-us/azure/templates/microsoft.storage/2019-06-01/storageaccounts/tableservices
{
"name": "default",
"type": "Microsoft.Storage/storageAccounts/tableServices",
"apiVersion": "2019-06-01",
"properties": {
"cors": {
"corsRules": [
{
"allowedOrigins": [
"string"
],
"allowedMethods": [
"string"
],
"maxAgeInSeconds": "integer",
"exposedHeaders": [
"string"
],
"allowedHeaders": [
"string"
]
}
]
}
}
}
和表格:
{
"name": "string",
"type": "Microsoft.Storage/storageAccounts/tableServices/tables",
"apiVersion": "2019-06-01"
}
目前只有容器可用。 Microsoft 正在开发表格。
从 2019-06-01 开始可以创建 Table 服务和 Tables。
Table 服务
{
"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": []
}
Tables
{
"name": "string",
"type": "Microsoft.Storage/storageAccounts/tableServices/tables",
"apiVersion": "2019-06-01"
}
我想通过一个答案来更新此内容,以便将来尝试使用 table 服务设置 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'))]"
]
}
用于在存储帐户中创建 Blob 和 Table 的示例 ARM 模板
{
"$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')]"
]
}
]
}
]
}
您可以在代码中使用 CreateIfNotExistsAsync 方法