在Azure中解决SubnetsHaveNoServiceEndpointsConfigured错误

38次阅读
没有评论

问题描述

在使用Terraform部署带有MongoDB的Azure CosmosDB账户时,遇到了SubnetsHaveNoServiceEndpointsConfigured错误。具体错误信息为:

Error: creating CosmosDB Account "geo-db-2pv0c" (Resource Group "geo"): waiting for the CosmosDB Account "geo-db-2pv0c" (Resource Group "geo") to finish creating/updating:
Code="BadRequest" Message="Database account creation failed. OperationId: b2f838e87b6c, Error : {
  "error": {
    "code":"SubnetsHaveNoServiceEndpointsConfigured",
    "message":"Subnets geo-internal-1 of virtual network/subscriptions/b5a3431d77a5/resourceGroups/geo/providers/Microsoft.Network/virtualNetworks/geo-network do not have ServiceEndpoints for Microsoft.AzureCosmosDB resources configured. Add Microsoft.AzureCosmosDB to subnet's ServiceEndpoints collection before trying to ACL Microsoft.AzureCosmosDB resources to these subnets.",
    "details": []
  }
}
ActivityId:95817ee8-801f-415d-ad06-06fd9af4130d,Microsoft.Azure.Documents.Common/2.14.0,Microsoft.Azure.Documents.Common/2.14.0,Microsoft.Azure.Documents.Common/2.14.0,Microsoft.Azure.Documents.Common/2.14.0,Microsoft.Azure.Documents.Common/2.14.0,Microsoft.Azure.Documents.Common/2.14.0,Microsoft.Azure.Documents.Common/2.14.0"

用户在错误信息中询问如何解决这个问题,以及如何将服务端点添加到子网中。

解决方案

在Azure中,SubnetsHaveNoServiceEndpointsConfigured错误通常是因为子网(Subnet)没有配置所需的服务终结点(Service Endpoints)。下面提供两种解决方案,你可以根据实际情况选择其中一种。

方案1:在Terraform中配置子网的服务终结点

如果你正在使用Terraform部署VNet和子网,可以通过配置子网的service_endpoints来添加所需的服务终结点。以下是配置子网的示例代码:

resource "azurerm_subnet" "subnet-internal-1" {
  name                 = "subnet-internal-1"
  resource_group_name  = azurerm_resource_group.geofriends.name
  virtual_network_name = azurerm_virtual_network.vnet-internal.name
  address_prefixes     = ["10.0.2.0/24"]

  service_endpoints = ["Microsoft.AzureCosmosDB"]
}

在上面的示例中,我们在子网配置中添加了service_endpoints属性,其中包含了需要的服务终结点,即Microsoft.AzureCosmosDB

方案2:手动配置子网的服务终结点

如果你已经部署了VNet和子网,可以手动通过Azure门户来配置子网的服务终结点。以下是步骤:

  1. 登录到Azure门户。
  2. 导航到你的VNet,并选择要添加服务终结点的子网。
  3. 在子网的设置中,找到“服务终结点”选项。
  4. 点击“添加服务终结点”按钮。
  5. 选择“Microsoft.AzureCosmosDB”作为要添加的服务。
  6. 保存更改。

这将会将所需的服务终结点添加到子网中,解决SubnetsHaveNoServiceEndpointsConfigured错误。

请注意,以上操作可能会因Azure门户界面的更新而略有不同。建议在操作之前先查阅官方文档或在线资源,确保你按照最新的步骤进行操作。

总结

在部署Azure CosmosDB账户时,出现SubnetsHaveNoServiceEndpointsConfigured错误通常是因为子网没有配置所需的服务终结点。你可以通过Terraform配置或手动操作来添加这些服务终结点,以解决这个错误。

正文完