From cf7a80a8cb7ec67207f259f86fc82f7a177761c6 Mon Sep 17 00:00:00 2001 From: Jason Harley Date: Tue, 13 Feb 2024 10:35:32 -0500 Subject: [PATCH] honeycombio: recipient resource support --- docs/honeycombio.md | 5 ++ providers/honeycombio/honeycomb_provider.go | 5 +- providers/honeycombio/recipient.go | 59 +++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 providers/honeycombio/recipient.go diff --git a/docs/honeycombio.md b/docs/honeycombio.md index 4fbf37383b..94d4db7cdb 100644 --- a/docs/honeycombio.md +++ b/docs/honeycombio.md @@ -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 diff --git a/providers/honeycombio/honeycomb_provider.go b/providers/honeycombio/honeycomb_provider.go index 6f2df1b0a5..58fa668c49 100644 --- a/providers/honeycombio/honeycomb_provider.go +++ b/providers/honeycombio/honeycomb_provider.go @@ -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 @@ -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{}{ @@ -131,5 +131,6 @@ func (p *HoneycombProvider) GetSupportedService() map[string]terraformutils.Serv "query_annotation": &QueryAnnotationGenerator{}, "slo": &SLOGenerator{}, "burn_alert": &BurnAlertGenerator{}, + "recipient": &RecipientGenerator{}, } } diff --git a/providers/honeycombio/recipient.go b/providers/honeycombio/recipient.go new file mode 100644 index 0000000000..dcf398c204 --- /dev/null +++ b/providers/honeycombio/recipient.go @@ -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 +}