Terraform-provider-azurerm: Terraform Run on cosmos-db account with consistency policy is giving inconsistent result

Created on 6 Aug 2019  ·  6Comments  ·  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform v0.12.6

  • provider.azurerm v1.32.1

Affected Resource(s)

  • azurerm_cosmosdb_account

Terraform Configuration Files

resource "azurerm_cosmosdb_account" "db" {
  name                = lookup(var.cosmosdb_account, "name", "default-cosmosdb-account")
  location            = var.location
  resource_group_name = var.resource_group_name
  offer_type          = lookup(var.cosmosdb_account, "offer_type", "Standard")
  kind                = lookup(var.cosmosdb_account, "kind", "GlobalDocumentDB")

  is_virtual_network_filter_enabled = lookup(var.cosmosdb_account, "is_virtual_network_filter_enabled", false)
  dynamic "virtual_network_rule" {
    for_each = lookup(var.cosmosdb_account, "is_virtual_network_filter_enabled", false) ? [lookup(var.cosmosdb_account), "virtual_network_rule"] : []
    content {
      id = virtual_network_rule.value
    }
  }
  enable_multiple_write_locations   = lookup(var.cosmosdb_account, "enable_multiple_write_locations", false)
  enable_automatic_failover         = lookup(var.cosmosdb_account, "enable_automatic_failover", true)

  consistency_policy {
    consistency_level       = lookup(var.cosmosdb_account, "consistency_level", "Session")
    max_interval_in_seconds = lookup(var.cosmosdb_account, "max_interval_in_seconds", null)
    max_staleness_prefix    = lookup(var.cosmosdb_account, "max_staleness_prefix", null)
  }

  geo_location {
    prefix            = lookup(var.cosmosdb_account, "geo_location_prefix", null)
    location          = var.location
    failover_priority = 0
  }

  dynamic "geo_location" {
    for_each = lookup(var.cosmosdb_account, "failover_location", "") == "" ? [] : [lookup(var.cosmosdb_account, "failover_location")] 
    content {
      location          = geo_location.value
      failover_priority = 1
    }
  }
}

variable "cosmosdb_account" {
  type = map(any)
  description = "Map that holds the cosmosdb_account configuration."
  default = {
    "name" = "unit-tests-tfm-azure-cosmosdb-failover",
    "geo_location_prefix" = "unit-tests-tf-azure-cosmosdb-endpoint",
    "failover_location" = "northeurope",
    "max_interval_in_seconds" = "300",
    "max_staleness_prefix" = "100000",
}


Debug Output

Panic Output

Expected Behavior

Successive terraform runs are idempotent on the cosmosdb-account resource

Actual Behavior

When applying, Azure does not seem to take the values for max_interval_in_seconds and max_staleness_prefix and instead putting 5 and 100 respectively in the state.
When now reapplying the configuration, terraform detects a change on those variables.

       ~ consistency_policy {
             consistency_level       = "Session"
           ~ max_interval_in_seconds = 5 -> 300
           ~ max_staleness_prefix    = 100 -> 100000
         }

Things are getting worse, when multiple geo_locations are configured, the azurerm provider needs only accepts values of >=300 and >=100000 respectively for the variables https://github.com/terraform-providers/terraform-provider-azurerm/blob/c5dc0c1edc976f19148aa598af5be61bb9aaec3d/azurerm/resource_arm_cosmosdb_account.go#L376
As a result, variable defaults cannot be used here.

Steps to Reproduce

  1. terraform apply
  2. terraform apply
bug serviccosmosdb waiting-response

Most helpful comment

still happening with version = 2.0 using the sample in the documentation linked above.

All 6 comments

The additional validation should only be required when the consistency_policy is set to BoundedStaleness.

Taking the following example out of the Provider Documentation yields the following result:

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

random_integer.ri: Destroying... [id=728954]
random_integer.ri: Destruction complete after 0s
random_integer.ri: Creating...
random_integer.ri: Creation complete after 0s [id=974582]
azurerm_cosmosdb_account.db: Creating...

Error: Error max_staleness_prefix (200) must be greater then 100000 when more then one geo_location is used

  on main.tf line 20, in resource "azurerm_cosmosdb_account" "db":
  20: resource "azurerm_cosmosdb_account" "db" {

Provider Version: =1.36.0

still happening with version = 2.0 using the sample in the documentation linked above.

Thanks for opening this issue. After tested with below tfconfig, I cannot repro it anymore. I assume this issue has been fixed from service side. Could you double check if this issue has been fixed?

provider "azurerm" {
  version = "1.32.1"
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-ca-test10"
  location = "eastus2"
}

resource "azurerm_cosmosdb_account" "test" {
  name                = "acctest-ca10"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name
  offer_type          = "Standard"

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

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

image

hi @sschne - given that @neil-yechenwei cannot reproduce the issue i am going to close this issue. Please reopen it if current versions of the provider are still not working correctly. Thanks!

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings