hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.59k stars 4.62k forks source link

`azurerm_cosmosdb_account` outputting wrong endpoint URL when using MongoDB #20306

Open joshwright10 opened 1 year ago

joshwright10 commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.3.6

AzureRM Provider Version

3.42.0

Affected Resource(s)/Data Source(s)

azurerm_cosmosdb_account

Terraform Configuration Files


terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.42.0"
    }

  }
  backend "local" {
    path = "terraform.tfstate"
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_cosmosdb_account" "this" {
  name                                  = "demo-cosmos-mangodb"
  location                              = azurerm_resource_group.this.location
  resource_group_name                   = azurerm_resource_group.this.name
  offer_type                            = "Standard"
  kind                                  = "MongoDB"
  is_virtual_network_filter_enabled     = true
  ip_range_filter                       = "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45,52.187.184.26"
  network_acl_bypass_for_azure_services = false
  public_network_access_enabled         = true
  enable_automatic_failover             = "UKWest"
  mongo_server_version                  = "4.0"

  capabilities { name = "EnableAggregationPipeline" }
  capabilities { name = "mongoEnableDocLevelTTL" }
  capabilities { name = "MongoDBv3.4" }
  capabilities { name = "EnableMongo" }

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

  geo_location {
    location          = "UKWest"
    failover_priority = 1
  }

  geo_location {
    location          = azurerm_resource_group.this.location
    failover_priority = 0
  }

  identity {
    type         = "SystemAssigned, UserAssigned"
    identity_ids = [azurerm_user_assigned_identity.this.id]
  }
}

resource "azurerm_resource_group" "this" {
  name     = "RG-Demo
  location = "uksouth"
}

resource "azurerm_user_assigned_identity" "this" {
  name                = "UID-Demo01"
  location            = azurerm_resource_group.this.location
  resource_group_name = azurerm_resource_group.this.name
}

Debug Output/Panic Output

https://gist.github.com/joshwright10/abe2bdc1e42f042de81512ac68b3b721#file-terraform-provider-azurerm-azurerm_cosmosdb_account-debug

Expected Behaviour

Attribute reference endpoint: https://demo-cosmos-mangodb.mongo.cosmos.azure.com:443/

Actual Behaviour

Attribute reference endpoint: https://demo-cosmos-mangodb.documents.azure.com:443/

Steps to Reproduce

terraform apply

Important Factoids

No response

References

No response

sinbai commented 1 year ago

@joshwright10 thanks for opening this issue. I would like to explain that the endpoint in Terraform corresponds to the documentEndpoint in Azure API. Per the following resource JSON data in the Azure portal, the documentEndpoint should be "https://demo-cosmos-mangodb.documents.azure.com:443/", the mongoEndpoint should be "https://demo-cosmos-mangodb.mongo.cosmos.azure.com:443/". So the endpoint in Terraform is documentEndpoint instead of mongoEndpoint. image

Terraform depends on the Azure API, the API does not expose property mongoEndpoint. Could you file an issue here requesting to expose mongoEndpoint if you need it? OncemongoEndpoint is available, terraform would follow up by priority.