terraform-provider-datadog icon indicating copy to clipboard operation
terraform-provider-datadog copied to clipboard

Cannot update Datadog Custom Metric Tag Configuration

Open aidanmelen opened this issue 1 year ago • 1 comments

Datadog Terraform Provider Version

3.43.1

Terraform Version

v1.5.7

What resources or data sources are affected?

datadog_metric_tag_configuration

Terraform Configuration Files

terraform {
  required_providers {
    datadog = {
      source  = "DataDog/datadog"
      version = "3.43.1"
    }
  }
}

provider "datadog" {}

resource "datadog_metric_tag_configuration" "example_metric" {
  metric_name         = "example.metric"
  metric_type         = "gauge"
  tags                = ["eks", "account"]
}

Relevant debug or panic output

Error: error creating MetricTagConfiguration from https://api.datadoghq.com/api/v2/metrics/void.upstream.duration.median/tags: 409 Conflict: {"errors":["New gauge/count/rate conflicts with existing tag configuration, use PATCH to update"]}

Expected Behavior

I would expect the datadog provider to patch the custom metric tags

Actual Behavior

The datadog provider throws a 409 conflict error.

Steps to Reproduce

  1. Find a custom metric
  2. manually updated the tags. e.g. reduce to just eks
  3. apply tags that are different than the manual changes. e.g. add account
resource "datadog_metric_tag_configuration" "example_metric" {
  metric_name         = "example.metric"
  metric_type         = "gauge"
  tags                = ["eks", "account"]
}

Important Factoids

No response

References

No response

aidanmelen avatar Aug 30 '24 16:08 aidanmelen

Any update on this issue????

juancarlosjr97 avatar Sep 24 '24 20:09 juancarlosjr97

Hello, looks like the error message posted, it is coming from the following line specifically in the Create call. Based on this, it seems like the metric you are trying to modify is not currently managed by terraform and needs to be brought into terraform state using the import command: https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/metric_tag_configuration#import Additionally, we use the metric_name as the ID so updating manually via UI will not generate new ids.

Could you try importing and see if the error persists?

skarimo avatar Nov 21 '24 15:11 skarimo

Based on this, it seems like the metric you are trying to modify is not currently managed by terraform and needs to be brought into terraform state using the import command

Sorry, the steps to reproduce are as follows.

  1. Find a custom metric
  2. Import the the custom metric to the datadog_metric_tag_configuration resource.
  3. Manually update the tags outside of terraform to create drift.
  4. Reapply the terraform and it will fail to correct the drift caused in step 2.

aidanmelen avatar Jan 02 '25 19:01 aidanmelen

Additionally, we use the metric_name as the ID so updating manually via UI will not generate new ids.

Terraform resource id's do not support .. you will get this error:

╷
│ Error: Invalid resource name
│ 
│   on main.tf line 61, in resource "datadog_metric_tag_configuration" "example.metric":
│   61: resource "datadog_metric_tag_configuration" "example.metric" {
│ 
│ A name must start with a letter or underscore and may contain only letters, digits, underscores, and dashes.
╵

aidanmelen avatar Jan 02 '25 19:01 aidanmelen

Based on this, it seems like the metric you are trying to modify is not currently managed by terraform and needs to be brought into terraform state using the import command

Sorry, the steps to reproduce are as follows.

  1. Find a custom metric
  2. Import the the custom metric to the datadog_metric_tag_configuration resource.
  3. Manually update the tags outside of terraform to create drift.
  4. Reapply the terraform and it will fail to correct the drift caused in step 2.

Hello !

I tested your scenariobut I didn't achieve to reproduce your issue . I tested it in 2 cases : from a resource created by Terraform and from a resource imported. I tested with the 3.52.1 provider version. Could you please retest with the 3.52.1 ?

ecdatadog avatar Jan 21 '25 12:01 ecdatadog

As said in the previous message, we were not able to reproduce your bug with recent version of the provider. Feel free to reopen (or create a new issue and link to this issue) if you still have the bug.

ecdatadog avatar May 16 '25 11:05 ecdatadog