Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

honeycombio: recipient resource support #1847

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/honeycombio.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export HONEYCOMB_API_KEY=MYAPIKEY
* `honeycombio_slo`
* `honeycombio_burn_alert`
* `honeycombio_derived_column`
* `recipient`
* `honeycombio_email_recipient`
* `honeycombio_pagerduty_recipient`
* `honeycombio_slack_recipient`
* `honeycombio_webhook_recipient`

#### A note about Environment-wide assets

Expand Down
5 changes: 3 additions & 2 deletions providers/honeycombio/honeycomb_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

const honeycombDefaultURL = "https://api.honeycomb.io"
const honeycombTerraformerProviderVersion = "0.0.2"
const honeycombTerraformerProviderVersion = "0.0.3"

type HoneycombProvider struct { //nolint
terraformutils.Provider
Expand All @@ -32,7 +32,7 @@ type HoneycombProvider struct { //nolint
datasets []string
}

func (p HoneycombProvider) GetProviderData(arg ...string) map[string]interface{} {
func (p HoneycombProvider) GetProviderData(_ ...string) map[string]interface{} {
return map[string]interface{}{
"provider": map[string]interface{}{
"honeycomb": map[string]interface{}{
Expand Down Expand Up @@ -131,5 +131,6 @@ func (p *HoneycombProvider) GetSupportedService() map[string]terraformutils.Serv
"query_annotation": &QueryAnnotationGenerator{},
"slo": &SLOGenerator{},
"burn_alert": &BurnAlertGenerator{},
"recipient": &RecipientGenerator{},
}
}
59 changes: 59 additions & 0 deletions providers/honeycombio/recipient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package honeycombio

import (
"context"
"fmt"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
hnyclient "github.com/honeycombio/terraform-provider-honeycombio/client"
)

type RecipientGenerator struct {
HoneycombService
}

func (g *RecipientGenerator) InitResources() error {
client, err := g.newClient()
if err != nil {
return fmt.Errorf("unable to initialize Honeycomb client: %v", err)
}

rcpts, err := client.Recipients.List(context.TODO())
if err != nil {
return fmt.Errorf("unable to list Honeycomb recipients: %v", err)
}

for _, rcpt := range rcpts {
var rcptResourceType string
var unsupportedRcpt bool

switch rcpt.Type {
case hnyclient.RecipientTypeEmail:
rcptResourceType = "honeycombio_email_recipient"
case hnyclient.RecipientTypePagerDuty:
rcptResourceType = "honeycombio_pagerduty_recipient"
case hnyclient.RecipientTypeSlack:
rcptResourceType = "honeycombio_slack_recipient"
case hnyclient.RecipientTypeWebhook:
rcptResourceType = "honeycombio_webhook_recipient"
default:
unsupportedRcpt = true
}
if unsupportedRcpt {
fmt.Printf("WARNING: unsupported recipient type: %s\n", rcpt.Type)
continue
}

g.Resources = append(g.Resources, terraformutils.NewResource(
rcpt.ID,
rcpt.ID,
rcptResourceType,
"honeycombio",
map[string]string{},
[]string{},
map[string]interface{}{},
))
}

return nil
}