data "azurerm_resource_group" "this" {
name = var.resource_group_name
}
resource "azurerm_cosmosdb_account" "this" {
name = local.cosmos_account_name
location = data.azurerm_resource_group.this.location
[...]
}
Absolutely every time I run plan/apply it wants to recreate the whole cosmosdb account because: location = "eastus" -> (known after apply) # forces replacement
But the location didn’t change, so I am a bit confused/annoyed with this behavior.
PS: I already tried to use location as a variable, but as the resource group is a data source, TF complains that I can’t set it, it needs to come from the data source.
What should I change to make this think work without recreating the whole account every time?
Can you show a more complete configuration, or the output of the plan? You have something preventing you from reading the azurerm_resource_group during the plan, and the full plan output or config will show why that is.
Since you have multiple data sources all with the deferral reason of
(depends on a resource or a module with changes pending)
I’m guessing that your module.mongo_cosmosdb module call is using depends_on and declaring that everything inside that module depends on some other pending changes. This prevents Terraform from determining more precise dependencies, and must wait until all the referenced changes have been applied in order to read the data sources. Using depends_on like that is almost always a mistake, and there’s always some other way to structure the configuration to get a more precise result.
absolutely right, I had the mongodb module with depends_on for a keyvault module output its ID. Didn’t know that would cause such problem. thx for the help, it solved my problem…