From 926ad4dbda60904c9e3858faf69cc7ea94bde5d4 Mon Sep 17 00:00:00 2001 From: Pete Davids <5599894+MisterSquishy@users.noreply.github.com> Date: Wed, 6 Mar 2024 12:50:35 -0500 Subject: [PATCH] adds `description` and `tooltip_fields` to the event query schema (#216) * probably fine * added terraform docs * version --------- Co-authored-by: MisterSquishy --- .go-version | 2 +- client/event_query.go | 12 +++--- docs/resources/event_query.md | 5 +++ lightstep/resource_event_query.go | 54 ++++++++++++++++++++++---- lightstep/resource_event_query_test.go | 9 +++++ 5 files changed, 68 insertions(+), 14 deletions(-) diff --git a/.go-version b/.go-version index 73e71c4b..dac58436 100644 --- a/.go-version +++ b/.go-version @@ -1,2 +1,2 @@ -1.91.7 +1.92.0 diff --git a/client/event_query.go b/client/event_query.go index 04792a4d..55d0714d 100644 --- a/client/event_query.go +++ b/client/event_query.go @@ -8,11 +8,13 @@ import ( ) type EventQueryAttributes struct { - ID string `json:"id"` - Name string `json:"name"` - QueryString string `json:"query_string"` - Source string `json:"source"` - Type string `json:"type"` + ID string `json:"id"` + Name string `json:"name"` + QueryString string `json:"query_string"` + Source string `json:"source"` + Type string `json:"type"` + Description string `json:"description"` + TooltipFields []string `json:"tooltip_fields"` } type WireEventQueryAttributes struct { diff --git a/docs/resources/event_query.md b/docs/resources/event_query.md index 8960acdc..69285a13 100644 --- a/docs/resources/event_query.md +++ b/docs/resources/event_query.md @@ -23,6 +23,11 @@ description: |- - `source` (String) - `type` (String) +### Optional + +- `description` (String) +- `tooltip_fields` (List of String) + ### Read-Only - `id` (String) The ID of this resource. diff --git a/lightstep/resource_event_query.go b/lightstep/resource_event_query.go index c4ad2136..b325ef1b 100644 --- a/lightstep/resource_event_query.go +++ b/lightstep/resource_event_query.go @@ -45,6 +45,17 @@ func resourceEventQuery() *schema.Resource { Type: schema.TypeString, Required: true, }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + "tooltip_fields": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, }, } } @@ -78,18 +89,37 @@ func resourceEventQueryRead(ctx context.Context, d *schema.ResourceData, m inter if err := d.Set("source", eq.Source); err != nil { return diag.FromErr(fmt.Errorf("unable to set query string: %v", err)) } + if err := d.Set("description", eq.Description); err != nil { + return diag.FromErr(fmt.Errorf("unable to set description: %v", err)) + } + if err := d.Set("tooltip_fields", eq.TooltipFields); err != nil { + return diag.FromErr(fmt.Errorf("unable to set tooltip fields: %v", err)) + } return diags } +func resourceDataToStringSlice(resourceData *schema.ResourceData, fieldName string) []string { + resource := resourceData.Get(fieldName) + + asInterfaceSlice := resource.([]interface{}) + stringSlice := make([]string, len(asInterfaceSlice)) + for i, element := range asInterfaceSlice { + stringSlice[i] = element.(string) + } + return stringSlice +} + func resourceEventQueryCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*client.Client) attrs := client.EventQueryAttributes{ - Type: d.Get("type").(string), - Name: d.Get("name").(string), - Source: d.Get("source").(string), - QueryString: d.Get("query_string").(string), + Type: d.Get("type").(string), + Name: d.Get("name").(string), + Source: d.Get("source").(string), + QueryString: d.Get("query_string").(string), + Description: d.Get("description").(string), + TooltipFields: resourceDataToStringSlice(d, "tooltip_fields"), } eq, err := c.CreateEventQuery(ctx, d.Get("project_name").(string), attrs) if err != nil { @@ -130,6 +160,12 @@ func resourceEventQueryImport(ctx context.Context, d *schema.ResourceData, m int if err := d.Set("source", eq.Source); err != nil { return nil, fmt.Errorf("unable to set query string: %v", err) } + if err := d.Set("description", eq.Description); err != nil { + return nil, fmt.Errorf("unable to set description: %v", err) + } + if err := d.Set("tooltip_fields", eq.TooltipFields); err != nil { + return nil, fmt.Errorf("unable to set tooltip fields: %v", err) + } return []*schema.ResourceData{d}, nil } @@ -137,10 +173,12 @@ func resourceEventQueryUpdate(ctx context.Context, d *schema.ResourceData, m int c := m.(*client.Client) attrs := client.EventQueryAttributes{ - Type: d.Get("type").(string), - Name: d.Get("name").(string), - Source: d.Get("source").(string), - QueryString: d.Get("query_string").(string), + Type: d.Get("type").(string), + Name: d.Get("name").(string), + Source: d.Get("source").(string), + QueryString: d.Get("query_string").(string), + Description: d.Get("description").(string), + TooltipFields: resourceDataToStringSlice(d, "tooltip_fields"), } eq, err := c.UpdateEventQuery(ctx, d.Get("project_name").(string), d.Id(), attrs) if err != nil { diff --git a/lightstep/resource_event_query_test.go b/lightstep/resource_event_query_test.go index 85358e35..b206d319 100644 --- a/lightstep/resource_event_query_test.go +++ b/lightstep/resource_event_query_test.go @@ -19,6 +19,8 @@ resource "lightstep_event_query" "terraform" { type = "test-type" source = "test-source" query_string = "logs" + description = "a test event query, for the terraform acceptance tests!" + tooltip_fields = ["foo", "bar"] } ` @@ -29,6 +31,7 @@ resource "lightstep_event_query" "terraform" { type = "test-type" source = "test-source" query_string = "logs | filter foo == bar" + description = "this is one heck of a query" } ` resource.Test(t, resource.TestCase{ @@ -44,6 +47,10 @@ resource "lightstep_event_query" "terraform" { resource.TestCheckResourceAttr("lightstep_event_query.terraform", "type", "test-type"), resource.TestCheckResourceAttr("lightstep_event_query.terraform", "source", "test-source"), resource.TestCheckResourceAttr("lightstep_event_query.terraform", "query_string", "logs"), + resource.TestCheckResourceAttr("lightstep_event_query.terraform", "description", "a test event query, for the terraform acceptance tests!"), + resource.TestCheckResourceAttr("lightstep_event_query.terraform", "tooltip_fields.#", "2"), + resource.TestCheckResourceAttr("lightstep_event_query.terraform", "tooltip_fields.0", "foo"), + resource.TestCheckResourceAttr("lightstep_event_query.terraform", "tooltip_fields.1", "bar"), ), }, { @@ -54,6 +61,8 @@ resource "lightstep_event_query" "terraform" { resource.TestCheckResourceAttr("lightstep_event_query.terraform", "type", "test-type"), resource.TestCheckResourceAttr("lightstep_event_query.terraform", "source", "test-source"), resource.TestCheckResourceAttr("lightstep_event_query.terraform", "query_string", "logs | filter foo == bar"), + resource.TestCheckResourceAttr("lightstep_event_query.terraform", "description", "this is one heck of a query"), + resource.TestCheckResourceAttr("lightstep_event_query.terraform", "tooltip_fields.#", "0"), ), }, },