通过terraform为天蓝色存储设置cors规则

问题描述 投票:0回答:3

我一直在网上看,我似乎找不到通过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中取出来调用它,还是有办法将它们绑在一起?

azure terraform azure-cli
3个回答

0
投票

如果有其他人遇到这个并想避免天蓝色臂模板的恐怖,那么这是我的修复,因为在这个时候写的没有任何东西:

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,否则每次运行都会创建新规则。


0
投票

我不认为你可以用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"
      }
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.