Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions datadog/resource_datadog_logs_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ var indexSchema = map[string]*schema.Schema{
Schema: exclusionFilterSchema,
},
},
"prevent_deletion": {
Description: "If true, the logs index cannot be deleted. Defaults to false.",
Type: schema.TypeBool,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having an explicit default here would make it consistent and auto-generated docs would benefit from it too, so the "Defaults to false" description could be removed.

},
}

var exclusionFilterSchema = map[string]*schema.Schema{
Expand Down Expand Up @@ -266,6 +271,11 @@ func resourceDatadogLogsIndexDelete(ctx context.Context, d *schema.ResourceData,

logsIndexMutex.Lock()
defer logsIndexMutex.Unlock()

if v, ok := d.GetOk("prevent_deletion"); ok && v.(bool) {
return diag.Errorf("Deletion of logs index '%s' is prevented by 'prevent_deletion' flag", d.Id())
}

httpResponse, err := apiInstances.GetLogsIndexesApiV1().DeleteLogsIndex(auth, d.Id())
if err != nil {
return utils.TranslateClientErrorDiag(err, httpResponse, "error deleting logs index")
Expand Down