Repository: honeycombio/terraform-provider-honeycombio
Pull request #198 (2022-07-27 23:17:01)

[columns] introducing `created_at`, `updated_at` and `last_written_at`
Adds additional fields available when working with Honeycomb Columns


Patch:
diff --git a/.gitignore b/.gitignore
index cada346..fe5e7db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,5 @@
 terraform-provider-honeycombio*
 
 coverage.txt
+
+.idea
diff --git a/client/column.go b/client/column.go
index 1a5e78f..24de62d 100644
--- a/client/column.go
+++ b/client/column.go
@@ -3,6 +3,7 @@ package client
 import (
 	"context"
 	"fmt"
+	"time"
 )
 
 // Columns describe all the columns-related methods that the Honeycomb API
@@ -56,6 +57,11 @@ type Column struct {
 	Description string `json:"description,omitempty"`
 	// Optional, defaults to string.
 	Type *ColumnType `json:"type,omitempty"`
+
+	// Read only
+	LastWrittenAt time.Time `json:"last_written,omitempty"`
+	CreatedAt     time.Time `json:"created_at,omitempty"`
+	UpdatedAt     time.Time `json:"updated_at,omitempty"`
 }
 
 // ColumnType determines the type of column.
diff --git a/docs/resources/column.md b/docs/resources/column.md
index 23b4990..da33907 100644
--- a/docs/resources/column.md
+++ b/docs/resources/column.md
@@ -35,6 +35,9 @@ The following arguments are supported:
 In addition to all arguments above, the following attributes are exported:
 
 * `id` - ID of the column.
+* `created_at` - ISO8601 formatted time the column was created
+* `updated_at` - ISO8601 formatted time the column was updated
+* `last_written_at` - ISO8601 formatted time the column was last written to (received event data)
 
 ## Import
 
diff --git a/honeycombio/resource_column.go b/honeycombio/resource_column.go
index ec7b519..0066e42 100644
--- a/honeycombio/resource_column.go
+++ b/honeycombio/resource_column.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"strings"
+	"time"
 
 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -47,6 +48,24 @@ func newColumn() *schema.Resource {
 				Required: true,
 				ForceNew: true,
 			},
+			"created_at": {
+				Type:     schema.TypeString,
+				Computed: true,
+				Required: false,
+				Optional: false,
+			},
+			"updated_at": {
+				Type:     schema.TypeString,
+				Computed: true,
+				Required: false,
+				Optional: false,
+			},
+			"last_written_at": {
+				Type:     schema.TypeString,
+				Computed: true,
+				Required: false,
+				Optional: false,
+			},
 		},
 	}
 }
@@ -107,6 +126,9 @@ func resourceColumnRead(ctx context.Context, d *schema.ResourceData, meta interf
 	d.Set("hidden", column.Hidden)
 	d.Set("description", column.Description)
 	d.Set("type", column.Type)
+	d.Set("created_at", column.CreatedAt.UTC().Format(time.RFC3339))
+	d.Set("updated_at", column.CreatedAt.UTC().Format(time.RFC3339))
+	d.Set("last_written_at", column.CreatedAt.UTC().Format(time.RFC3339))
 	return nil
 }
 


Test patch:
diff --git a/client/column_test.go b/client/column_test.go
index 14d8496..16823d9 100644
--- a/client/column_test.go
+++ b/client/column_test.go
@@ -28,7 +28,15 @@ func TestColumns(t *testing.T) {
 		assert.NoError(t, err)
 
 		data.ID = column.ID
+		assert.NotNil(t, column.LastWrittenAt, "last written at is empty")
+		assert.NotNil(t, column.CreatedAt, "created at is empty")
+		assert.NotNil(t, column.UpdatedAt, "updated at is empty")
+		// copy dynamic fields before asserting equality
+		data.LastWrittenAt = column.LastWrittenAt
+		data.CreatedAt = column.CreatedAt
+		data.UpdatedAt = column.UpdatedAt
 		assert.Equal(t, data, column)
+
 	})
 
 	t.Run("List", func(t *testing.T) {
@@ -66,7 +74,13 @@ func TestColumns(t *testing.T) {
 		assert.NoError(t, err)
 
 		data.ID = column.ID
-		assert.Equal(t, data, column)
+		assert.NotNil(t, column.LastWrittenAt, "last written at is empty")
+		assert.NotNil(t, column.CreatedAt, "created at is empty")
+		assert.NotNil(t, column.UpdatedAt, "updated at is empty")
+		// copy dynamic fields before asserting equality
+		data.LastWrittenAt = column.LastWrittenAt
+		data.CreatedAt = column.CreatedAt
+		data.UpdatedAt = column.UpdatedAt
 	})
 
 	t.Run("Delete", func(t *testing.T) {