使用 Terraform 阻止允许共享访问密钥

Prevent Allow Shared Access Key using Terraform

嘿,我目前正在使用 Terraform v0.12.28 和提供商 azurerm v2.22.0 我想在 Azure 存储中禁用(允许共享访问密钥,允许 Blob public 访问,并使用 TLS1_2)配置使其安全,我发现“allow_blob_public_access = false”和“min_tls_version =”TLS1_2”但无法找到禁用允许共享访问密钥的参数。

resource "azurerm_storage_account" "main" {
  name                     = var.storage_account_name
  resource_group_name      = azurerm_resource_group.main.name
  location                 = azurerm_resource_group.main.location
  account_tier             = var.account_tier
  account_replication_type = var.account_replication_type
  allow_blob_public_access = false
  min_tls_version = "TLS1_2"
  

}  

Terraform中没有设置Allow Shared Access Key的选项,这只是说明Terraform不支持​​此功能,Azure中的此功能也是预览版。还有另一种方法可以在 Azure 门户旁边设置允许共享访问密钥

这种方式是通过Terraform中的local-exec使用Azure CLI:

resource "null_resource" "example" {
  provisioner "local-exec" {
    command = "az resource update --ids ${azurerm_storage_account.main.id} --set properties.allowSharedKeyAccess=false"
  }
}

您可以获得有关允许共享访问密钥的更多详细信息here

这是较新版本提供程序中的一项功能。我相信在 2.73 中引入:

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account#shared_access_key_enabled