Skip to content

Commit

Permalink
honeycombio_column: delete column on destroy (#258)
Browse files Browse the repository at this point in the history
Since the provider's inception this resource treated deletes as a 'noop'
-- simply removing the column from state.

In 0.12.0 we removed the silent import of an existing column on create
which has forced this gap into the light.

Given that column deletes are fully supported in the API, it felt proper
to enable them here as it is assumed that the operator understands that
there is removal.

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1203644387911130
  • Loading branch information
jharley authored Jan 10, 2023
1 parent 9063789 commit ee4dc51
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
9 changes: 6 additions & 3 deletions docs/resources/column.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Resource: honeycombio_column

Creates a column in a dataset.
Provides a Honeycomb Column resource.
This can be used to create, update, and delete columns in a dataset.

-> **Note** Destroying or replacing this resource will not delete the previously created column. This is intentional to preserve the column and its data. The API supports deleting columns, so if this is required for your use case please open an issue in [honeycombio/terraform-provider-honeycombio](https://github.com/honeycombio/terraform-provider-honeycombio).
-> **Note**: deleting a column is a destructive and irreversible operation which also removes the data in the column.

-> **Note**: prior to version 0.13.0 of the provider, columns were *not* deleted on destroy but left in place and only removed from state.

## Example Usage

Expand All @@ -11,7 +14,7 @@ variable "dataset" {
type = string
}
resource "honeycombio_column" "duration_ms" {
resource "honeycombio_column" "duration_ms" {
name = "duration_ms_log10"
type = "float"
description = "Duration of the trace"
Expand Down
14 changes: 13 additions & 1 deletion honeycombio/resource_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func newColumn() *schema.Resource {
CreateContext: resourceColumnCreate,
ReadContext: resourceColumnRead,
UpdateContext: resourceColumnUpdate,
DeleteContext: schema.NoopContext,
DeleteContext: resourceColumnDelete,
Importer: &schema.ResourceImporter{
StateContext: resourceColumnImport,
},
Expand Down Expand Up @@ -159,6 +159,18 @@ func resourceColumnUpdate(ctx context.Context, d *schema.ResourceData, meta inte
return resourceColumnRead(ctx, d, meta)
}

func resourceColumnDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*honeycombio.Client)

dataset := d.Get("dataset").(string)

err := client.Columns.Delete(ctx, dataset, d.Id())
if err != nil {
return diag.FromErr(err)
}
return nil
}

func expandColumn(d *schema.ResourceData) *honeycombio.Column {
// if name is not set, try to get key_name.
// The schema requires one or the other to be set
Expand Down
13 changes: 13 additions & 0 deletions honeycombio/resource_column_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package honeycombio

import (
"context"
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccHoneycombioColumn_basic(t *testing.T) {
Expand Down Expand Up @@ -34,6 +36,17 @@ func TestAccHoneycombioColumn_basic(t *testing.T) {
ImportStateVerify: true,
},
},
CheckDestroy: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
// ensure column is removed on destroy
client := testAccClient(t)
_, err := client.Columns.GetByKeyName(context.Background(), dataset, keyName)
if err == nil {
return fmt.Errorf("column %q was not deleted on destroy", keyName)
}
return nil
},
),
})
}

Expand Down

0 comments on commit ee4dc51

Please sign in to comment.