我正在尝试通过Azure devOps管道(terraform)部署azure存储帐户,配置如下:存储帐户,具有“blob”专用服务连接的专用端点。 当我第一次部署它时,它成功并使用私有 DNS 区域成功创建了私有端点。稍后,使用相同的配置进行第二次运行时,我遇到错误:
错误:检索存储帐户的静态网站属性(订阅:“qwerty12345”
│ 资源组名称:“qwerty-01”
│ 存储帐户名称: "storage01"): 执行请求: 获取 "https://storage01.blob.core.windows.net/?comp=properties&restype=service": 拨打 tcp: 查找 storage01.blob.core.windows.net上
如果我删除之前创建的存储帐户并再次运行,它将成功创建资源。我不明白为什么它在第二次管道运行中给我一个错误。
您遇到的错误是由于 DNS 解析造成的。
为 Azure 存储帐户创建专用终结点时,无法再直接访问 Azure 存储帐户公共终结点 (
storage01.blob.core.windows.net
);相反,您应该使用链接到私有 DNS 区域的专用端点。
确保专用 DNS 区域已正确配置并链接到虚拟网络。 DNS 设置应将
storagevehgjgnkat.blob.core.windows.net
解析为专用端点的专用 IP,而不是公共 IP。
创建私有 DNS 区域并将其链接到 VNet 后,DNS 传播可能需要一些时间。稍等片刻,然后运行第二条管道
以下是创建具有专用终结点、DNS 区域和 VNet 链接的存储帐户的代码
provider "azurerm" {
features {}
subscription_id = "8332bf56-aa7c-4daa-a507-d7e60e5f09a9"
}
resource "azurerm_resource_group" "example" {
name = "qwerty-01"
location = "East US"
lifecycle {
ignore_changes = all
}
}
resource "azurerm_virtual_network" "example" {
name = "example-vnet"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "example" {
name = "example-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.1.0/24"]
}
resource "azurerm_storage_account" "example" {
name = "storagevehgjgnkat"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
is_hns_enabled = true # For enabling hierarchical namespace (for ADLS Gen2)
}
resource "azurerm_private_endpoint" "example" {
name = "example-private-endpoint"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
subnet_id = azurerm_subnet.example.id
private_service_connection {
name = "example-blob-connection"
private_connection_resource_id = azurerm_storage_account.example.id
is_manual_connection = false
subresource_names = ["blob"]
}
}
resource "azurerm_private_dns_zone" "example" {
name = "privatelink.blob.core.windows.net"
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_private_dns_a_record" "example" {
name = "storage01"
zone_name = azurerm_private_dns_zone.example.name
resource_group_name = azurerm_resource_group.example.name
ttl = 300
records = [azurerm_private_endpoint.example.private_service_connection[0].private_ip_address]
}
resource "azurerm_private_dns_zone_virtual_network_link" "example" {
name = "example-vnet-link"
resource_group_name = azurerm_resource_group.example.name
private_dns_zone_name = azurerm_private_dns_zone.example.name
virtual_network_id = azurerm_virtual_network.example.id
}
output "storage_account_name" {
value = azurerm_storage_account.example.name
}
已为存储帐户的专用终结点创建 DNS 记录。创建记录后,它将通过 VNet 的私有 IP 解析存储帐户。