cockroachdb / terraform-provider-cockroach

Terraform provider for CockroachDB Cloud
Apache License 2.0
56 stars 10 forks source link

Error when deleting cockroach_metric_export_datadog_config #117

Closed uLan08 closed 1 year ago

uLan08 commented 1 year ago

I get errors when I delete the cockroach_metric_export_datadog_config resource. At first, I thought it was an ordering thing, so I added a depends_on to guarantee the order but it didn't help.

│ Error: Error deleting Datadog metric export config
│
│ Could not delete Datadog metric export config: couldn't lock cluster

After running the terraform destroy command again, I get another error which blocks me from proceeding unless I do terraform state rm. This error tells me that the resource on CockroachDB side has actually been deleted.

│ Error: Error getting Datadog metric export info
│
│   with module.cockroachdb_dedicated.cockroach_metric_export_datadog_config.datadog_export[0],
│   on ../../metric_log_export.tf line 25, in resource "cockroach_metric_export_datadog_config" "datadog_export":
│   25: resource "cockroach_metric_export_datadog_config" "datadog_export" {
│
│ Unexpected error retrieving Datadog metric export info: couldn't find a Datadog metric export config for the cluster

Terraform code

resource "cockroach_metric_export_datadog_config" "datadog_export" {
  count   = var.enable_datadog_integration ? 1 : 0
  id      = cockroach_cluster.cluster.id
  site    = "US1"
  api_key = var.datadog_api_key

  depends_on = [
    cockroach_cluster.cluster,
  ]
}

Terraform versions

▶ terraform version
Terraform v1.3.7
on darwin_amd64
+ provider registry.terraform.io/cockroachdb/cockroach v0.4.7
+ provider registry.terraform.io/hashicorp/aws v4.67.0
uLan08 commented 1 year ago

encountered a similar issue during creation. doesn't happen all the time tho.

│ Error: Error enabling log export
│
│   with module.cockroachdb_dedicated.cockroach_log_export_config.export[0],
│   on ../../metric_log_export.tf line 85, in resource "cockroach_log_export_config" "export":
│   85: resource "cockroach_log_export_config" "export" {
│
│ Could not enable log export: failed to acquire cluster lock

Is it possible that cockroach_log_export_config and cockroach_metric_export_datadog_config are competing for the lock?

erademacher commented 1 year ago

@jenngeorge would you mind taking a look at this? Looks like log and metric export both lock the cluster, so we should add similar checks to the those in the cluster resource.

jenngeorge commented 1 year ago

@erademacher Yes, thanks for tagging me! I'm on vacation next week, but can take a look & add the checks when I return the week of 6/5.

jenngeorge commented 1 year ago

Just following up: I'm back from vacation & plan to start on this tomorrow.

erademacher commented 1 year ago

Fixed in v0.6.0.