我正在尝试在Azure子网中创建具有私有终结点的存储帐户。
terraform apply
之后,我遇到了这样的问题:
创建专用端点“ dev-pe”(资源组)时出错 “ privateendpoint-rg”):network.PrivateEndpointsClient#CreateOrUpdate: 发送请求失败:StatusCode = 400-原始错误: Code =“ PrivateEndpointCannotBeCreatedInSubnetThatHasNetworkPoliciesEnabled” Message =“私人端点 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/privateendpoint-rg/providers/Microsoft.Network/privateEndpoints/dev-pe 不能在子网中创建 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/privateendpoint-rg/providers/Microsoft.Network/virtualNetworks/dev-vnet/subnets/dev-storage-subnet 因为它启用了专用端点网络策略。“ Details = []
如下所示,我设置了enforce_private_link_endpoint_network_policies = false
并与azurem_private_link_service
一起玩。
这是我的代码:
resource "azurerm_resource_group" "example" {
name = "privateendpoint-rg"
location = var.location
tags = local.common_tags
}
resource "azurerm_virtual_network" "example" {
name = "${var.environment}-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
tags = local.common_tags
}
resource "azurerm_subnet" "storage" {
name = "${var.environment}-storage-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefix = "10.0.1.0/24"
enforce_private_link_endpoint_network_policies = false
// enforce_private_link_service_network_policies = false
// service_endpoints = ["Microsoft.Storage"]
}
resource "random_integer" "sa_num" {
min = 10000
max = 99999
}
resource "azurerm_storage_account" "example" {
name = "${var.adoit_number}${lower(var.environment)}${random_integer.sa_num.result}"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
enable_https_traffic_only = true
tags = local.common_tags
}
resource "azurerm_storage_container" "example" {
name = "acctestcont"
storage_account_name = azurerm_storage_account.example.name
container_access_type = "private"
}
resource "azurerm_private_endpoint" "example" {
name = "${var.environment}-pe"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
subnet_id = azurerm_subnet.storage.id
private_service_connection {
name = "${var.environment}-psc"
is_manual_connection = false
private_connection_resource_id = azurerm_storage_account.example.id
subresource_names = ["blob"]
}
}
如果我更改enforce_private_link_endpoint_network_policies = true
,则会收到以下错误消息:
创建专用端点“ dev-pe”(资源组)时出错 “ privateendpoint-rg”): network.PrivateEndpointsClient#CreateOrUpdate:发送失败 请求:StatusCode = 400-原始错误: Code =“ OperationNotAllowedOnKind” Message =“不允许该操作 帐户类型的存储”详细信息= []
答案 0 :(得分:3)
确定,找到了。
如果要将存储帐户连接到专用端点,则该存储帐户必须为StorageV2
类型,其在Terraform代码中的显示如下:
resource "azurerm_storage_account" "example" {
name = "${var.adoit_number}${lower(var.environment)}${random_integer.sa_num.result}"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_kind = "StorageV2"
account_tier = "Standard"
account_replication_type = "LRS"
enable_https_traffic_only = true
tags = local.common_tags
}