<p>The service endpoint is an Azure requirement; there's no change you could make to the CosmosDB deployment which will get around that.</p>
<p>Assuming you are also deploying the vnet and subnet through Terraform, then I guess you need to specify the service endpoint when you do so; see <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet#service_endpoints" rel="nofollow noreferrer">azurerm_subnet</a>.</p>

CC BY-SA 4.0
2021-12-23T06:23:03.597Z
Also found "ignore_missing_vnet_service_endpoint = true" but this seems better, thanks
Serve Laurijssen
CC BY-SA 4.0
2021-12-22T14:01:45.717Z
2021-12-22T14:01:45.717Z
Vince Bowdren
<p>I'm trying to deploy cosmosdb account with mongodb on azure with terraform.
But 'terraform apply' times out with SubnetsHaveNoServiceEndpointsConfigured error.</p>
<blockquote>
<p>Error: creating CosmosDB Account &quot;geo-db-2pv0c&quot; (Resource Group
&quot;geo&quot;): waiting for the CosmosDB Account &quot;geo-db-2pv0c&quot;
(Resource Group &quot;geo&quot;) to finish creating/updating:
Code=&quot;BadRequest&quot; Message=&quot;Database account creation failed. Operation
Id: b2f838e87b6c, Error : {\r\n  &quot;error&quot;: {\r\n    &quot;code&quot;:
&quot;SubnetsHaveNoServiceEndpointsConfigured&quot;,\r\n    &quot;message&quot;:
&quot;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.&quot;,\r\n    &quot;details&quot;: []\r\n  }\r\n}\r\nActivityId:
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&quot; │ │   with
azurerm_cosmosdb_account.db, │   on azure_cosmosdb.tf line 9, in
resource &quot;azurerm_cosmosdb_account&quot; &quot;db&quot;: │    9: resource
&quot;azurerm_cosmosdb_account&quot; &quot;db&quot; {</p>
</blockquote>
<p>There is no info on this error and how to that endpoint to a subnet. Anyone knows how to do that?</p>
<pre><code>resource &quot;azurerm_cosmosdb_account&quot; &quot;db&quot; {
  name                = &quot;geofriends-db-${random_string.random-name.result}&quot;
  location            = azurerm_resource_group.geofriends.location
  resource_group_name = azurerm_resource_group.geofriends.name
  offer_type          = &quot;Standard&quot;
  kind                = &quot;MongoDB&quot;

  enable_automatic_failover = true

  is_virtual_network_filter_enabled = true

  virtual_network_rule {
    id = azurerm_subnet.subnet-internal-1.id
  }

  capabilities {
    name = &quot;EnableMongo&quot;
  }

  capabilities {
    name = &quot;MongoDBv3.4&quot;
  }

  consistency_policy {
    consistency_level       = &quot;BoundedStaleness&quot;
    max_interval_in_seconds = 300
    max_staleness_prefix    = 100000
  }

  geo_location {
    prefix            = &quot;cosmosdb-s${random_string.random-name.result}-failover&quot;
    location          = var.failover_location
    failover_priority = 1
  }

  geo_location {
    prefix            = &quot;cosmosdb-s${random_string.random-name.result}-main&quot;
    location          = azurerm_resource_group.geofriends.location
    failover_priority = 0
  }
}
</code></pre>

<terraform><azure><mongodb>
SubnetsHaveNoServiceEndpointsConfigured error when deplying cosmosdb account
Serve Laurijssen
# SubnetsHaveNoServiceEndpointsConfigured error when deplying cosmosdb account

(Asked by: username_0 on 2021-12-22)

I'm trying to deploy cosmosdb account with mongodb on azure with terraform.
But 'terraform apply' times out with SubnetsHaveNoServiceEndpointsConfigured error.

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. Operation
Id: b2f838e87b6c, Error : {\r\n  "error": {\r\n    "code":
"SubnetsHaveNoServiceEndpointsConfigured",\r\n    "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.",\r\n    "details": []\r\n  }\r\n}\r\nActivityId:
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" │ │   with
azurerm_cosmosdb_account.db, │   on azure_cosmosdb.tf line 9, in
resource "azurerm_cosmosdb_account" "db": │    9: resource
"azurerm_cosmosdb_account" "db" {

There is no info on this error and how to that endpoint to a subnet. Anyone knows how to do that?
resource "azurerm_cosmosdb_account" "db" {
  name                = "geofriends-db-${random_string.random-name.result}"
  location            = azurerm_resource_group.geofriends.location
  resource_group_name = azurerm_resource_group.geofriends.name
  offer_type          = "Standard"
  kind                = "MongoDB"

  enable_automatic_failover = true

  is_virtual_network_filter_enabled = true

  virtual_network_rule {
    id = azurerm_subnet.subnet-internal-1.id
  }

  capabilities {
    name = "EnableMongo"
  }

  capabilities {
    name = "MongoDBv3.4"
  }

  consistency_policy {
    consistency_level       = "BoundedStaleness"
    max_interval_in_seconds = 300
    max_staleness_prefix    = 100000
  }

  geo_location {
    prefix            = "cosmosdb-s${random_string.random-name.result}-failover"
    location          = var.failover_location
    failover_priority = 1
  }

  geo_location {
    prefix            = "cosmosdb-s${random_string.random-name.result}-main"
    location          = azurerm_resource_group.geofriends.location
    failover_priority = 0
  }
}

**Tags:** terraform, azure, mongodb


---

## 1 answers

### Answer by username_1 on 2021-12-22. Score: 1 | Accepted answer

The service endpoint is an Azure requirement; there's no change you could make to the CosmosDB deployment which will get around that.

Assuming you are also deploying the vnet and subnet through Terraform, then I guess you need to specify the service endpoint when you do so; see [azurerm\_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet#service_endpoints).

> **Comments:**
> **username_0**: Also found "ignore_missing_vnet_service_endpoint = true" but this seems better, thanks  

---

