Skip to content

Commit

Permalink
Add event query ids (#207)
Browse files Browse the repository at this point in the history
* add eventqueries

* add test

* fmt

* add project name

* update function

* Test

* remove

* why?

* acceptance tests

* acceptance tests

* run tfdocs step

* hey its me

* branch

* branch

* maybe

* origin

* Actual checkout

* correct email

* push

* origin

* origin

* origin2

* different

* test

* test

* test

* rever

* Revert "rever"

This reverts commit 79a62c6.

* Reapply "rever"

This reverts commit 5cdfcbc.

* whoops

* Revert "whoops"

This reverts commit 318f271.

* test

* view remote

* view remote

* view remote

* view remote

* v3

* this?

* creds

* v3

* organize

* Author

* switch

* switch

* fetch depth 0

* don't persist creds

* need that

* version

* added terraform docs

---------

Co-authored-by: danhurwit <[email protected]>
  • Loading branch information
danhurwit and danhurwit authored Feb 12, 2024
1 parent bb16ff0 commit 3ee2eaa
Show file tree
Hide file tree
Showing 12 changed files with 488 additions and 19 deletions.
34 changes: 21 additions & 13 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
contents: read

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
Expand All @@ -31,30 +31,38 @@ jobs:
name: Run tfplugindocs
runs-on: ubuntu-latest
permissions:
contents: read

contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false

ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: '1.20.5' # tfplugindocs requires go >= 1.18

- name: Setup tfplugindocs
run: |
cd /tmp
curl -L -o tfplugindocs.zip https://github.com/hashicorp/terraform-plugin-docs/releases/download/v0.15.0/tfplugindocs_0.15.0_linux_amd64.zip
unzip tfplugindocs.zip
chmod +x tfplugindocs
- name: Compare generated files with checked in files
- name: Generate tf docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
rm -r docs
/tmp/tfplugindocs
git diff --stat --exit-code ./docs
- name: Commit And Push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name ${{ github.actor }}
git add .
git commit -m "added terraform docs"
git push
terraform_lint:

name: Run terraform-lint
Expand All @@ -63,7 +71,7 @@ jobs:
contents: read

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
Expand All @@ -87,7 +95,7 @@ jobs:
go-version: '1.20.5'

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup terraform CLI
uses: hashicorp/setup-terraform@v1
Expand Down Expand Up @@ -116,7 +124,7 @@ jobs:
go-version: '1.20.5'

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup terraform CLI
uses: hashicorp/setup-terraform@v1
Expand Down
3 changes: 2 additions & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
1.90.0
1.91.0

87 changes: 87 additions & 0 deletions client/event_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package client

import (
"context"
"encoding/json"
"fmt"
"net/http"
)

type EventQueryAttributes struct {
ID string `json:"id"`
Name string `json:"name"`
QueryString string `json:"query_string"`
Source string `json:"source"`
Type string `json:"type"`
}

type WireEventQueryAttributes struct {
Attributes EventQueryAttributes `json:"attributes"`
}

func (c *Client) GetEventQuery(ctx context.Context, projectName string, eventQueryID string) (*EventQueryAttributes, error) {
var (
event *WireEventQueryAttributes
resp Envelope
)

if err := c.CallAPI(ctx, "GET", fmt.Sprintf("projects/%v/event_queries/%v",
projectName, eventQueryID), nil, &resp); err != nil {
return nil, err
}
if err := json.Unmarshal(resp.Data, &event); err != nil {
return nil, err
}
return &event.Attributes, nil
}

func (c *Client) CreateEventQuery(ctx context.Context, projectName string, attributes EventQueryAttributes) (*EventQueryAttributes, error) {
var (
event *EventQueryAttributes
resp Envelope
)

body := WireEventQueryAttributes{Attributes: attributes}
bytes, err := json.Marshal(body)
if err != nil {
return event, err
}
if err := c.CallAPI(ctx, "POST",
fmt.Sprintf("projects/%v/event_queries", projectName), Envelope{Data: bytes}, &resp); err != nil {
return nil, err
}
err = json.Unmarshal(resp.Data, &event)
return event, err
}

func (c *Client) UpdateEventQuery(ctx context.Context, projectName string, eventQueryID string, attributes EventQueryAttributes) (*EventQueryAttributes, error) {
var (
event *EventQueryAttributes
resp Envelope
)

bytes, err := json.Marshal(attributes)
if err != nil {
return event, err
}
if err := c.CallAPI(ctx, "PUT",
fmt.Sprintf("projects/%v/event_queries/%v", eventQueryID, projectName), bytes, &resp); err != nil {
return nil, err
}
err = json.Unmarshal(resp.Data, &event)
return event, err
}

func (c *Client) DeleteEventQuery(ctx context.Context, projectName string, eventQueryID string) error {
err := c.CallAPI(ctx, "DELETE",
fmt.Sprintf("projects/%v/event_queries/%v", projectName, eventQueryID),
nil,
nil)
if err != nil {
apiClientError, ok := err.(APIResponseCarrier)
if !ok || apiClientError.GetStatusCode() != http.StatusNoContent {
return err
}
}
return nil
}
2 changes: 2 additions & 0 deletions client/metric_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type UnifiedDashboardAttributes struct {
Groups []UnifiedGroup `json:"groups"`
Labels []Label `json:"labels"`
TemplateVariables []TemplateVariable `json:"template_variables"`
EventQueryIDs []string `json:"event_query_ids"`
}

type UnifiedGroup struct {
Expand Down Expand Up @@ -112,6 +113,7 @@ func (c *Client) CreateUnifiedDashboard(
Groups: dashboard.Attributes.Groups,
Labels: dashboard.Attributes.Labels,
TemplateVariables: dashboard.Attributes.TemplateVariables,
EventQueryIDs: dashboard.Attributes.EventQueryIDs,
},
})

Expand Down
1 change: 1 addition & 0 deletions docs/resources/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ resource "lightstep_dashboard" "customer_charges" {

- `chart` (Block Set) (see [below for nested schema](#nestedblock--chart))
- `dashboard_description` (String)
- `event_query_ids` (Set of String) IDs of the event queries to display on this dashboard
- `group` (Block Set) (see [below for nested schema](#nestedblock--group))
- `label` (Block Set) Labels can be key/value pairs or standalone values. (see [below for nested schema](#nestedblock--label))
- `template_variable` (Block Set) Variable to be used in dashboard queries for dynamically filtering telemetry data (see [below for nested schema](#nestedblock--template_variable))
Expand Down
28 changes: 28 additions & 0 deletions docs/resources/event_query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "lightstep_event_query Resource - terraform-provider-lightstep"
subcategory: ""
description: |-
---

# lightstep_event_query (Resource)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String)
- `project_name` (String) Lightstep project name
- `query_string` (String)
- `source` (String)
- `type` (String)

### Read-Only

- `id` (String) The ID of this resource.
1 change: 1 addition & 0 deletions docs/resources/metric_dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ resource "lightstep_metric_dashboard" "customer_charges" {

- `chart` (Block Set) (see [below for nested schema](#nestedblock--chart))
- `dashboard_description` (String)
- `event_query_ids` (Set of String) IDs of the event queries to display on this dashboard
- `group` (Block Set) (see [below for nested schema](#nestedblock--group))
- `label` (Block Set) Labels can be key/value pairs or standalone values. (see [below for nested schema](#nestedblock--label))
- `template_variable` (Block Set) Variable to be used in dashboard queries for dynamically filtering telemetry data (see [below for nested schema](#nestedblock--template_variable))
Expand Down
1 change: 1 addition & 0 deletions lightstep/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func Provider() *schema.Provider {
"lightstep_user_role_binding": resourceUserRoleBinding(),
"lightstep_inferred_service_rule": resourceInferredServiceRule(),
"lightstep_saml_group_mappings": resourceSAMLGroupMappings(),
"lightstep_event_query": resourceEventQuery(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down
Loading

0 comments on commit 3ee2eaa

Please sign in to comment.