Skip to content

Commit

Permalink
Merge branch 'main' into cewkrupa/include-request-id-in-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jharley authored Dec 6, 2024
2 parents bd2a59e + 29a81ed commit 17f6cf7
Show file tree
Hide file tree
Showing 12 changed files with 1,324 additions and 66 deletions.
24 changes: 2 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
name: Test US
needs: build
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 20
concurrency:
group: hnytf-testacc-us
env:
Expand All @@ -58,15 +58,13 @@ jobs:
./scripts/setup-testsuite-dataset
- name: Run client acceptance tests
timeout-minutes: 10
env:
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }}
HONEYCOMB_KEY_ID: ${{ secrets.HONEYCOMB_KEY_ID }}
HONEYCOMB_KEY_SECRET: ${{ secrets.HONEYCOMB_KEY_SECRET }}
HONEYCOMB_DATASET: testacc
run: |
go test -v ./client/... \
-coverprofile=client-coverage.txt \
-covermode=atomic | \
go-junit-report \
-set-exit-code \
Expand All @@ -79,7 +77,6 @@ jobs:
terraform_wrapper: false

- name: Run TF acceptance tests
timeout-minutes: 10
env:
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }}
HONEYCOMB_KEY_ID: ${{ secrets.HONEYCOMB_KEY_ID }}
Expand All @@ -89,7 +86,6 @@ jobs:
TF_ACC_TERRAFORM_VERSION: ${{ env.TERRAFORM_VERSION }}
run: |
go test -v ./internal/... ./honeycombio/... \
-coverprofile=tf-coverage.txt \
-covermode=atomic | \
go-junit-report \
-set-exit-code \
Expand All @@ -110,7 +106,6 @@ jobs:
- name: Cleanup Dangling Resources
if: ${{ always() }}
timeout-minutes: 5
env:
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }}
HONEYCOMB_KEY_ID: ${{ secrets.HONEYCOMB_KEY_ID }}
Expand All @@ -125,16 +120,11 @@ jobs:
paths: "*-report.xml"
show: "fail, skip"

- name: Generate Coverage Report
uses: codecov/codecov-action@v4.6.0
with:
token: ${{ secrets.CODECOV_TOKEN }}

test-eu:
name: Test EU
needs: build
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 20
concurrency:
group: hnytf-testacc-eu
env:
Expand All @@ -159,7 +149,6 @@ jobs:
./scripts/setup-testsuite-dataset
- name: Run client acceptance tests
timeout-minutes: 10
env:
HONEYCOMB_API_ENDPOINT: https://api.eu1.honeycomb.io
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY_EU }}
Expand All @@ -168,7 +157,6 @@ jobs:
HONEYCOMB_DATASET: testacc
run: |
go test -v ./client/... \
-coverprofile=client-coverage.txt \
-covermode=atomic | \
go-junit-report \
-set-exit-code \
Expand All @@ -181,7 +169,6 @@ jobs:
terraform_wrapper: false

- name: Run TF acceptance tests
timeout-minutes: 10
env:
HONEYCOMB_API_ENDPOINT: https://api.eu1.honeycomb.io
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY_EU }}
Expand All @@ -192,7 +179,6 @@ jobs:
TF_ACC_TERRAFORM_VERSION: ${{ env.TERRAFORM_VERSION }}
run: |
go test -v ./internal/... ./honeycombio/... \
-coverprofile=tf-coverage.txt \
-covermode=atomic | \
go-junit-report \
-set-exit-code \
Expand All @@ -213,7 +199,6 @@ jobs:
- name: Cleanup Dangling Resources
if: ${{ always() }}
timeout-minutes: 5
env:
HONEYCOMB_API_ENDPOINT: https://api.eu1.honeycomb.io
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY_EU }}
Expand All @@ -228,8 +213,3 @@ jobs:
with:
paths: "*-report.xml"
show: "fail, skip"

- name: Generate Coverage Report
uses: codecov/codecov-action@v4.6.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Any new additions should be built with the Plugin Framework.
* The Plugin SDK-based code is contained in the `honeycombio/` directory in the root of the repository.
* The Plugin Framework-based code is contained in the `internal/provider` directory.

Any PRs reimplmenting Plugin SDKv2 resources or datasources in the Plugin Framework with be enthusiastically accepted. 🙏
Any PRs reimplementing Plugin SDKv2 resources or datasources in the Plugin Framework will be enthusiastically accepted. 🙏

### Preview document changes

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![OSS Lifecycle](https://img.shields.io/osslifecycle/honeycombio/terraform-provider-honeycombio)](https://github.com/honeycombio/home/blob/main/honeycomb-oss-lifecycle-and-practices.md)
[![CI](https://github.com/honeycombio/terraform-provider-honeycombio/workflows/CI/badge.svg)](https://github.com/honeycombio/terraform-provider-honeycombio/actions)
[![codecov](https://codecov.io/gh/honeycombio/terraform-provider-honeycombio/branch/main/graph/badge.svg)](https://codecov.io/gh/honeycombio/terraform-provider-honeycombio)
[![Terraform Registry](https://img.shields.io/github/v/release/honeycombio/terraform-provider-honeycombio?color=5e4fe3&label=Terraform%20Registry&logo=terraform&sort=semver)](https://registry.terraform.io/providers/honeycombio/honeycombio/latest)

A Terraform provider for Honeycomb.io.
Expand Down
30 changes: 29 additions & 1 deletion client/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,41 @@ type RecipientDetails struct {
WebhookName string `json:"webhook_name,omitempty"`
WebhookURL string `json:"webhook_url,omitempty"`
// webhook only
WebhookSecret string `json:"webhook_secret,omitempty"`
WebhookSecret string `json:"webhook_secret,omitempty"`
WebhookHeaders []WebhookHeader `json:"webhook_headers"`
// custom webhook
WebhookPayloads *WebhookPayloads `json:"webhook_payloads,omitempty"`
}

type NotificationRecipientDetails struct {
PDSeverity PagerDutySeverity `json:"pagerduty_severity,omitempty"`
}

type WebhookPayloads struct {
PayloadTemplates PayloadTemplates `json:"payload_templates"`
TemplateVariables []TemplateVariable `json:"template_variables"`
}

type PayloadTemplates struct {
Trigger *PayloadTemplate `json:"trigger,omitempty"`
ExhaustionTime *PayloadTemplate `json:"exhaustion_time,omitempty"`
BudgetRate *PayloadTemplate `json:"budget_rate,omitempty"`
}

type PayloadTemplate struct {
Body string `json:"body"`
}

type TemplateVariable struct {
Name string `json:"name"`
Default string `json:"default_value"`
}

type WebhookHeader struct {
Key string `json:"header"`
Value string `json:"value"`
}

// RecipientType holds all the possible recipient types.
type RecipientType string

Expand Down
59 changes: 59 additions & 0 deletions client/recipient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,65 @@ func TestRecipientsEmail(t *testing.T) {
})
}

func TestRecipientsCustomWebhook(t *testing.T) {
t.Parallel()

ctx := context.Background()
c := newTestClient(t)

body := `{"hello": "world"}`

testCases := []struct {
rcpt client.Recipient
expectErr bool
}{
{
rcpt: client.Recipient{
Type: client.RecipientTypeWebhook,
Details: client.RecipientDetails{
WebhookName: test.RandomStringWithPrefix("test.", 10),
WebhookURL: test.RandomURL(),
WebhookSecret: "secret",
WebhookHeaders: []client.WebhookHeader{{Key: "Authorization", Value: "Bearer 123"}},
WebhookPayloads: &client.WebhookPayloads{
PayloadTemplates: client.PayloadTemplates{Trigger: &client.PayloadTemplate{Body: body}},
TemplateVariables: []client.TemplateVariable{{Name: "severity", Default: "warning"}},
},
},
},
},
}

for _, tc := range testCases {
tr := tc.rcpt
t.Run(tr.Type.String(), func(t *testing.T) {
r, err := c.Recipients.Create(ctx, &tr)
t.Cleanup(func() {
_ = c.Recipients.Delete(ctx, r.ID)
})

if tc.expectErr {
require.Error(t, err, "expected error creating %s recipient", tr.Type)
return
}
require.NoError(t, err, "failed to create %s recipient", tr.Type)
r, err = c.Recipients.Get(ctx, r.ID)
require.NoError(t, err)

assert.Equal(t, tr.Type, r.Type)
assert.Equal(t, tr.Details.WebhookName, r.Details.WebhookName)
assert.Equal(t, tr.Details.WebhookURL, r.Details.WebhookURL)
assert.Equal(t, tr.Details.WebhookSecret, r.Details.WebhookSecret)
assert.Equal(t, tr.Details.WebhookPayloads, r.Details.WebhookPayloads)
assert.Equal(t, tr.Details.WebhookPayloads.TemplateVariables, r.Details.WebhookPayloads.TemplateVariables)
if assert.Len(t, r.Details.WebhookHeaders, 1) {
assert.Equal(t, tr.Details.WebhookHeaders[0].Key, r.Details.WebhookHeaders[0].Key)
assert.Equal(t, tr.Details.WebhookHeaders[0].Value, r.Details.WebhookHeaders[0].Value)
}
})
}
}

func TestRecipientsWebhooksandMSTeams(t *testing.T) {
t.Parallel()

Expand Down
61 changes: 60 additions & 1 deletion docs/resources/webhook_recipient.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`honeycombio_webhook_recipient` allows you to define and manage a Webhook recipient that can be used by Triggers or BurnAlerts notifications.

## Example Usage
## Standard Webhook Example

```hcl
resource "honeycombio_webhook_recipient" "prod" {
Expand All @@ -12,13 +12,72 @@ resource "honeycombio_webhook_recipient" "prod" {
}
```

## Custom Webhook Example

```hcl
resource "honeycombio_webhook_recipient" "prod" {
name = "Production Alerts"
secret = "a63dab148496ecbe04a1a802ca9b95b8"
url = "https://my.url.corp.net"
header {
name = "Authorization"
value = "Bearer 123"
}
template {
type = "trigger"
body = <<EOT
{
"name": " {{ .Name }}",
"id": " {{ .ID }}",
"description": " {{ .Description }}",
"threshold": {
"op": "{{ .Operator }}",
"value": "{{ .Threshold }}"
},
}
EOT
}
variable {
name = "severity"
default_value = "critical"
}
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the Webhook Integration to create.
* `secret` - (Optional) The secret to include when sending the notification to the webhook.
* `url` - (Required) The URL of the endpoint to send the notification to.
* `template` - (Optional) Zero or more configuration blocks (described below) to customize the webhook payload if desired.
* `variable` - (Optional) Zero or more configuration blocks (described below) to define variables to be used in the webhook payload if desired.
* `header` - (Optional) Zero or more configuration blocks (described below) to add custom webhook headers if desired.

When configuring custom webhook payloads, use the `template` block, which accepts the following arguments:

* `type` - (Required) The template type, allowed types are `trigger`, `exhaustion_time`, and `budget_rate`. Only one template block of each type is allowed on a single recipient.
* `body` - (Required) A JSON formatted string to represent the webhook payload.

Optionally, when configuring custom webhooks, use the `variable` block to create custom variables that can be interpolated in a template.
To configure a variable, at least one `template` block must also be configured.
The `variable` block accepts the following arguments:

* `name` - (Required) The name of the custom variable. Must be an alphanumeric string beginning with a lowercase letter.
* `default_value` - (Optional) The default value for the custom variable, which can be overridden at the alert level.

Optionally, when configuring custom webhooks, use the `header` block to create custom HTTP headers to be included in the webhook request.
Up to five custom headers can be configured. Reserved headers `Content-Type`, `User-Agent`, and `X-Honeycomb-Webhook-Token` cannot be used.
The `header` block accepts the following arguments:

* `name` - (Required) The name or key for the header.
* `value` - (Optional) The value for the header.



## Attribute Reference

Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ require (
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-mux v0.17.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/hashicorp/terraform-plugin-testing v1.10.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
)

require (
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
)
Expand All @@ -41,7 +41,7 @@ require (
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hc-install v0.9.0 // indirect
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.23.0 // indirect
Expand All @@ -63,11 +63,11 @@ require (
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
Expand Down
Loading

0 comments on commit 17f6cf7

Please sign in to comment.