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

Delete log indexes

Open marceloboeira opened this issue 2 years ago • 5 comments

It seems that it is now possible to delete indexes via the UI (not having to create a support ticket anymore) which makes it possible to eventually manage them via terraform.

Screenshot 2022-06-06 at 10 36 52

Happy to open an MR implementing the delete, however, I can't find anything in the docs about a public API endpoint for doing that being available.

The only reference from the app's UI is to an endpoint which guess is limited to UI via cross-origin/authentication token...

Screenshot 2022-06-06 at 11 13 21

Are there any plans to include this behavior in the public API?

Affected Resource(s)

  • datadog_logs_index

Expected Behavior

Log Index gets deleted if the resource is present in TF state ...

Open Questions

What happens when one updates an index name? should it be deleted/recreated?

References

marceloboeira avatar Jun 06 '22 09:06 marceloboeira

This bug in the DataDog Terraform Provider has caused me a lot of grief.

Terraform can:

  • create indexes
  • add index to the order
  • delete index from the order

Terraform cannot:

  • delete index

The impact of this bug is as follows:

  • If you create a datadog_logs_index resource and append its id to a datadog_logs_index_order resource, Terraform will successfully create the index and successfully add it to the index order.
  • If you then want to remove the index via Terraform and simultaneously remove it from the index order, Terraform will output the following:
datadog_logs_index.sample_index: Destroying... [id=sample-index]
datadog_logs_index.sample_index: Destruction complete after 0s
datadog_logs_index_order.dd_log_order: Modifying... [id=dd_log_order]
╷
│ Error: error updating logs index list from https://api.datadoghq.com/api/v1/logs/config/index-order: 422 Unprocessable Entity: {"error":{"message":"Invalid list of indexes","code":"UnprocessableEntity"}}
│ 
│ 
│   with datadog_logs_index_order.dd_log_order,
│   on index.tf line 3, in resource "datadog_logs_index_order" "dd_log_order":
│    3: resource "datadog_logs_index_order" "dd_log_order" {

This is because the datadog_logs_index has been removed from Terraform but still exists in DataDog because Delete Index is not a DataDog API action (so of course, Terraform cannot perform it). And Terraform is attempting to remove an existing index from the index log order, but DataDog requires that every existing index be in the index log order.

The manual solution is to perform the above (getting the error), then go into DataDog and manually delete the index, and then go back to Terraform and re-run the terraform apply.

Note: I have not confirmed the solution because I do not have permissions to delete indices in my organization.

wcoqscwx avatar Aug 03 '22 22:08 wcoqscwx

Just to add to this. If a delete_index command on Datadog was immediate this isn't a problem. However if you have an index with a retention period of 14 days ( the default ), guess how long it takes to delete the index !? 14 days ! Therefore your whole terraform build will fail for the next 14 days, until it's gone from datadog. Very annoying. Terraform / Datadog need some better way of dealing with resource that take a long time ( days ) to delete !

mikecouk avatar Feb 07 '23 15:02 mikecouk

14 days ! Therefore your whole terraform build will fail for the next 14 days, until it's gone from datadog. Very annoying.

Did DD support confirm this?

That's really annoying, but as an "immediate" solution, one can simply remove it from the state manually to avoid problems on plan/apply...

marceloboeira avatar Feb 07 '23 19:02 marceloboeira

This is yet another missing core feature (of a long list) for an enterprise-oriented service and I'm now convinced this company is a flake, they focus only on appearances to boost sales, completely neglecting features consistency and completeness.

SharpEdgeMarshall avatar Apr 13 '23 10:04 SharpEdgeMarshall

There is still no Delete API in documents. https://docs.datadoghq.com/api/latest/logs-indexes/

waneal avatar Apr 23 '24 14:04 waneal