Skip to content

Commit

Permalink
fix: handling importing columns and derived columns with slashes in t…
Browse files Browse the repository at this point in the history
…he name
  • Loading branch information
jharley committed Feb 16, 2024
1 parent d92499c commit d0ee37a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
3 changes: 3 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func TestClient_InvalidConfig(t *testing.T) {
func TestClient_IsClassic(t *testing.T) {
t.Parallel()

// load environment values from a .env, if available
_ = godotenv.Load("../.env")

ctx := context.Background()
apiKey, ok := os.LookupEnv(client.DefaultAPIKeyEnv)
if !ok {
Expand Down
14 changes: 6 additions & 8 deletions honeycombio/resource_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package honeycombio
import (
"context"
"errors"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -88,14 +87,13 @@ func newColumn() *schema.Resource {

func resourceColumnImport(ctx context.Context, d *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) {
// import ID is of the format <dataset>/<column name>
// note that the dataset name can also contain '/'
idSegments := strings.Split(d.Id(), "/")
if len(idSegments) < 2 {
return nil, fmt.Errorf("invalid import ID, supplied ID must be written as <dataset>/<column name>")
importID := d.Id()
idx := strings.Index(importID, "/")
if idx < 0 {
return nil, errors.New("invalid import ID, supplied ID must be written as <dataset>/<column name>")
}

dataset := strings.Join(idSegments[0:len(idSegments)-1], "/")
name := idSegments[len(idSegments)-1]
dataset := importID[:idx]
name := importID[idx+1:]

d.Set("name", name)
d.Set("dataset", dataset)
Expand Down
14 changes: 6 additions & 8 deletions honeycombio/resource_derived_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package honeycombio
import (
"context"
"errors"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -51,14 +50,13 @@ func newDerivedColumn() *schema.Resource {

func resourceDerivedColumnImport(ctx context.Context, d *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) {
// import ID is of the format <dataset>/<derived column alias>
// note that the dataset name can also contain '/'
idSegments := strings.Split(d.Id(), "/")
if len(idSegments) < 2 {
return nil, fmt.Errorf("invalid import ID, supplied ID must be written as <dataset>/<derived column alias>")
importID := d.Id()
idx := strings.Index(importID, "/")
if idx < 0 {
return nil, errors.New("invalid import ID, supplied ID must be written as <dataset>/<derived column alias>")
}

dataset := strings.Join(idSegments[0:len(idSegments)-1], "/")
alias := idSegments[len(idSegments)-1]
dataset := importID[:idx]
alias := importID[idx+1:]

d.Set("alias", alias)
d.Set("dataset", dataset)
Expand Down

0 comments on commit d0ee37a

Please sign in to comment.