我一直在网上寻找,但我似乎找不到一种通过terraform设置cors规则的方法。
我不相信它在terraform中得到了支持。
可以通过az cli设置CORS规则:
azure storage cors set --blob static
--cors "[{\"AllowedOrigins\":\"*\",\"AllowedMethods\":\"GET\",\"MaxAgeInSeconds\":\"86400\",\"AllowedHeaders\":\"*\",\"ExposedHeaders\":\"*\"}]"
-a "account-name" -k "account-key" --verbose
我可以从terraform中调用它吗?或者有没有一种方法可以将它们捆绑在一起?
发布于 2019-03-13 08:22:17
如果其他任何人遇到这个问题,并想要避免蓝色手臂模板的恐怖,那么这是我的解决方案,因为在撰写本文时还没有terraform:
resource "null_resource" "storage" {
provisioner "local-exec" {
command = "az storage cors clear --account-name ${azurerm_storage_account.main.name} --services b"
}
provisioner "local-exec" {
command = "az storage cors add --account-name ${azurerm_storage_account.main.name} --origins '*' --methods GET POST PUT --allowed-headers 'Accept-Ranges,Content-Encoding,Content-Length,Content-Type,Range,Authorization,x-ms-blob-content-type,x-ms-blob-type,x-ms-version' --exposed-headers 'Accept-Ranges,Content-Range,Content-Encoding,Content-Length,Content-Type' --max-age 86400 --services b"
}
}
我必须调用az storage cors clear
,否则每次运行时都会创建新规则。
发布于 2019-03-12 05:29:10
我不认为你能用Terraform (proof)做到这一点。您可以使用前面提到的ARM模板,也可以通过配置器使用Terraform中的脚本资源(Azure CLI,就像您提到的那样)。
示例ARM模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2015-06-15",
"name": "[concat('storage', uniqueString(resourceGroup().id))]",
"location": "[resourceGroup().location]",
"properties": {
"accountType": "Standard_LRS",
"cors": {
"allowedHeaders": [ "*" ],
"allowedMethods": [ "get", "post", "put" ],
"allowedOrigins": [ "*" ],
"exposedHeaders": [ "*" ],
"maximumAge": 5
},
"val": "123"
}
}
]
}
发布于 2019-03-12 00:10:57
https://stackoverflow.com/questions/55110784
复制