From dd05ad7796449fce4d1a03ea983c3939467ff0fe Mon Sep 17 00:00:00 2001 From: brookesargent Date: Fri, 20 Dec 2024 07:59:37 -0500 Subject: [PATCH 1/6] first pass at stubbing out alert variable data structures --- client/recipient.go | 8 +- internal/models/notification_recipients.go | 12 +++ internal/provider/notification_recipients.go | 82 ++++++++++++++++++- .../provider/notification_recipients_test.go | 2 +- 4 files changed, 100 insertions(+), 4 deletions(-) diff --git a/client/recipient.go b/client/recipient.go index e5e90e4f..33b01e09 100644 --- a/client/recipient.go +++ b/client/recipient.go @@ -71,8 +71,14 @@ type RecipientDetails struct { WebhookPayloads *WebhookPayloads `json:"webhook_payloads,omitempty"` } +type NotificationVariable struct { + Name string `json:"name"` + Value string `json:"value"` +} + type NotificationRecipientDetails struct { - PDSeverity PagerDutySeverity `json:"pagerduty_severity,omitempty"` + Variables []NotificationVariable `json:"variables,omitempty"` + PDSeverity PagerDutySeverity `json:"pagerduty_severity,omitempty"` } type WebhookPayloads struct { diff --git a/internal/models/notification_recipients.go b/internal/models/notification_recipients.go index e6ef1ff0..bcc1d6d7 100644 --- a/internal/models/notification_recipients.go +++ b/internal/models/notification_recipients.go @@ -23,8 +23,20 @@ var NotificationRecipientAttrType = map[string]attr.Type{ type NotificationRecipientDetailsModel struct { PDSeverity types.String `tfsdk:"pagerduty_severity"` + Variables types.Set `tfsdk:"variable"` } var NotificationRecipientDetailsAttrType = map[string]attr.Type{ "pagerduty_severity": types.StringType, + "variable": types.SetType{ElemType: types.ObjectType{AttrTypes: NotificationVariableAttrType}}, +} + +type NotificationVariableModel struct { + Name types.String `tfsdk:"name"` + Value types.String `tfsdk:"value"` +} + +var NotificationVariableAttrType = map[string]attr.Type{ + "name": types.StringType, + "value": types.StringType, } diff --git a/internal/provider/notification_recipients.go b/internal/provider/notification_recipients.go index e48f69a4..fb736269 100644 --- a/internal/provider/notification_recipients.go +++ b/internal/provider/notification_recipients.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -13,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" @@ -85,6 +87,33 @@ func notificationRecipientSchema(allowedTypes []client.RecipientType) schema.Set }, }, }, + "variable": schema.SetNestedBlock{ + Description: "The variables to set with the Webhook notification.", + Validators: []validator.Set{ + setvalidator.SizeAtMost(10), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Required: true, + Description: "The name of the variable", + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 64), + stringvalidator.RegexMatches(webhookTemplateNameRegex, "must be an alphanumeric string beginning with a lowercase letter"), + }, + }, + "value": schema.StringAttribute{ + Description: "An optional default value for the variable", + Optional: true, + Computed: true, + Default: stringdefault.StaticString(""), + Validators: []validator.String{ + stringvalidator.LengthAtMost(256), + }, + }, + }, + }, + }, }, }, } @@ -155,8 +184,10 @@ func expandNotificationRecipients(ctx context.Context, set types.Set, diags *dia if diags.HasError() { return nil } + rcpt.Details = &client.NotificationRecipientDetails{ PDSeverity: client.PagerDutySeverity(details[0].PDSeverity.ValueString()), + Variables: expandNotificationVariables(ctx, details[0].Variables, diags), } } clientRecips[i] = rcpt @@ -207,7 +238,8 @@ func notificationRecipientModelToObjectValue(ctx context.Context, r models.Notif if diags.HasError() { return basetypes.ObjectValue{} } - detailsObjVal, d := types.ObjectValue(models.NotificationRecipientDetailsAttrType, map[string]attr.Value{"pagerduty_severity": details[0].PDSeverity}) + + detailsObjVal, d := types.ObjectValue(models.NotificationRecipientDetailsAttrType, map[string]attr.Value{"pagerduty_severity": details[0].PDSeverity, "variable": details[0].Variables}) diags.Append(d...) result, d = types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.NotificationRecipientDetailsAttrType}, []attr.Value{detailsObjVal}) diags.Append(d...) @@ -236,7 +268,7 @@ func notificationRecipientToModel(ctx context.Context, r client.NotificationReci func notificationRecipientDetailsToList(ctx context.Context, details *client.NotificationRecipientDetails, diags *diag.Diagnostics) basetypes.ListValue { var result basetypes.ListValue if details != nil { - detailsObj := map[string]attr.Value{"pagerduty_severity": types.StringValue(string(details.PDSeverity))} + detailsObj := map[string]attr.Value{"pagerduty_severity": types.StringValue(string(details.PDSeverity)), "variable": flattenNotificationVariables(ctx, details.Variables, diags)} objVal, d := types.ObjectValue(models.NotificationRecipientDetailsAttrType, detailsObj) diags.Append(d...) result, d = types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.NotificationRecipientDetailsAttrType}, []attr.Value{objVal}) @@ -247,3 +279,49 @@ func notificationRecipientDetailsToList(ctx context.Context, details *client.Not return result } + +func notificationVariableToObjectValue(v client.NotificationVariable, diags *diag.Diagnostics) basetypes.ObjectValue { + variableObj := map[string]attr.Value{ + "name": types.StringValue(v.Name), + "value": types.StringValue(v.Value), + } + varObjVal, d := types.ObjectValue(models.NotificationVariableAttrType, variableObj) + diags.Append(d...) + + return varObjVal +} + +func flattenNotificationVariables(ctx context.Context, vars []client.NotificationVariable, diags *diag.Diagnostics) types.Set { + if len(vars) == 0 || vars == nil { + return types.SetNull(types.ObjectType{AttrTypes: models.NotificationVariableAttrType}) + } + + var notifVarValues []attr.Value + for _, v := range vars { + notifVarValues = append(notifVarValues, notificationVariableToObjectValue(v, diags)) + } + notifVarResult, d := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.WebhookHeaderAttrType}, notifVarValues) + diags.Append(d...) + + return notifVarResult +} + +func expandNotificationVariables(ctx context.Context, set types.Set, diags *diag.Diagnostics) []client.NotificationVariable { + var notifVars []models.NotificationVariableModel + diags.Append(set.ElementsAs(ctx, ¬ifVars, false)...) + if diags.HasError() { + return nil + } + + clientNotifVars := make([]client.NotificationVariable, len(notifVars)) + for i, v := range notifVars { + notifVar := client.NotificationVariable{ + Name: v.Name.ValueString(), + Value: v.Value.ValueString(), + } + + clientNotifVars[i] = notifVar + } + + return clientNotifVars +} diff --git a/internal/provider/notification_recipients_test.go b/internal/provider/notification_recipients_test.go index d8b90fa9..5c58432c 100644 --- a/internal/provider/notification_recipients_test.go +++ b/internal/provider/notification_recipients_test.go @@ -150,5 +150,5 @@ func notificationRecipientModelsToSet(n []models.NotificationRecipientModel) typ } func severityStringToValue(s string) []attr.Value { - return []attr.Value{types.ObjectValueMust(models.NotificationRecipientDetailsAttrType, map[string]attr.Value{"pagerduty_severity": types.StringValue(s)})} + return []attr.Value{types.ObjectValueMust(models.NotificationRecipientDetailsAttrType, map[string]attr.Value{"pagerduty_severity": types.StringValue(s), "variable": types.SetNull(types.ObjectType{AttrTypes: models.NotificationVariableAttrType})})} } From 3931259b4b34c45280270f40aa20b51e5f3e5adb Mon Sep 17 00:00:00 2001 From: brookesargent Date: Fri, 20 Dec 2024 09:10:39 -0500 Subject: [PATCH 2/6] make sure the schema defines variable in the right place --- internal/provider/notification_recipients.go | 48 ++++++++++---------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/internal/provider/notification_recipients.go b/internal/provider/notification_recipients.go index fb736269..1421379b 100644 --- a/internal/provider/notification_recipients.go +++ b/internal/provider/notification_recipients.go @@ -85,30 +85,32 @@ func notificationRecipientSchema(allowedTypes []client.RecipientType) schema.Set }, }, }, - }, - }, - "variable": schema.SetNestedBlock{ - Description: "The variables to set with the Webhook notification.", - Validators: []validator.Set{ - setvalidator.SizeAtMost(10), - }, - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Required: true, - Description: "The name of the variable", - Validators: []validator.String{ - stringvalidator.LengthBetween(1, 64), - stringvalidator.RegexMatches(webhookTemplateNameRegex, "must be an alphanumeric string beginning with a lowercase letter"), + Blocks: map[string]schema.Block{ + "variable": schema.SetNestedBlock{ + Description: "The variables to set with the webhook notification.", + Validators: []validator.Set{ + setvalidator.SizeAtMost(10), }, - }, - "value": schema.StringAttribute{ - Description: "An optional default value for the variable", - Optional: true, - Computed: true, - Default: stringdefault.StaticString(""), - Validators: []validator.String{ - stringvalidator.LengthAtMost(256), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Required: true, + Description: "The name of the variable", + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 64), + stringvalidator.RegexMatches(webhookTemplateNameRegex, "must be an alphanumeric string beginning with a lowercase letter"), + }, + }, + "value": schema.StringAttribute{ + Description: "The variable value", + Optional: true, + Computed: true, + Default: stringdefault.StaticString(""), + Validators: []validator.String{ + stringvalidator.LengthAtMost(256), + }, + }, + }, }, }, }, From 3d1448f90a4858f9e4c89db703f93a3bc749a368 Mon Sep 17 00:00:00 2001 From: brookesargent Date: Fri, 20 Dec 2024 10:26:34 -0500 Subject: [PATCH 3/6] add some burn alert tests --- internal/provider/burn_alert_resource_test.go | 227 +++++++++++++++++- 1 file changed, 225 insertions(+), 2 deletions(-) diff --git a/internal/provider/burn_alert_resource_test.go b/internal/provider/burn_alert_resource_test.go index 56c8280f..c7bd4019 100644 --- a/internal/provider/burn_alert_resource_test.go +++ b/internal/provider/burn_alert_resource_test.go @@ -119,6 +119,38 @@ func TestAcc_BurnAlertResource_exhaustionTimeBasic(t *testing.T) { }) } +func TestAcc_BurnAlertResource_exhaustionTimeBasicWebhookRecipient(t *testing.T) { + dataset, sloID := burnAlertAccTestSetup(t) + burnAlert := &client.BurnAlert{} + exhaustionMinutes := 240 + + resource.Test(t, resource.TestCase{ + PreCheck: testAccPreCheck(t), + ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory, + CheckDestroy: testAccEnsureBurnAlertDestroyed(t), + Steps: []resource.TestStep{ + // Create - basic + { + Config: testAccConfigBurnAlertExhaustionTime_basicWebhookRecipient(exhaustionMinutes, dataset, sloID, "warning"), + Check: testAccEnsureSuccessExhaustionTimeAlertWithWebhookRecip(t, burnAlert, exhaustionMinutes, sloID, "warning"), + }, + // Update - change variable value + { + Config: testAccConfigBurnAlertExhaustionTime_basicWebhookRecipient(exhaustionMinutes, dataset, sloID, "info"), + Check: testAccEnsureSuccessExhaustionTimeAlertWithWebhookRecip(t, burnAlert, exhaustionMinutes, sloID, "info"), + }, + // Import + { + ResourceName: "honeycombio_burn_alert.test", + ImportStateIdPrefix: fmt.Sprintf("%v/", dataset), + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"recipient"}, + }, + }, + }) +} + func TestAcc_BurnAlertResource_budgetRateBasic(t *testing.T) { dataset, sloID := burnAlertAccTestSetup(t) burnAlert := &client.BurnAlert{} @@ -169,6 +201,39 @@ func TestAcc_BurnAlertResource_budgetRateBasic(t *testing.T) { }) } +func TestAcc_BurnAlertResource_budgetRateBasicWebhookRecipient(t *testing.T) { + dataset, sloID := burnAlertAccTestSetup(t) + burnAlert := &client.BurnAlert{} + budgetRateWindowMinutes := 60 + budgetRateDecreasePercent := float64(5) + + resource.Test(t, resource.TestCase{ + PreCheck: testAccPreCheck(t), + ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory, + CheckDestroy: testAccEnsureBurnAlertDestroyed(t), + Steps: []resource.TestStep{ + // Create - basic + { + Config: testAccConfigBurnAlertBudgetRate_basicWebhookRecipient(budgetRateWindowMinutes, budgetRateDecreasePercent, dataset, sloID, "warning"), + Check: testAccEnsureSuccessBudgetRateAlertWithWebhookRecip(t, burnAlert, budgetRateWindowMinutes, budgetRateDecreasePercent, sloID, "warning"), + }, + // Update - change variable value + { + Config: testAccConfigBurnAlertBudgetRate_basicWebhookRecipient(budgetRateWindowMinutes, budgetRateDecreasePercent, dataset, sloID, "info"), + Check: testAccEnsureSuccessBudgetRateAlertWithWebhookRecip(t, burnAlert, budgetRateWindowMinutes, budgetRateDecreasePercent, sloID, "info"), + }, + // Import + { + ResourceName: "honeycombio_burn_alert.test", + ImportStateIdPrefix: fmt.Sprintf("%v/", dataset), + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"recipient"}, + }, + }, + }) +} + // Check that creating a budget rate alert with a // budget_rate_decrease_percent with trailing zeros works, // doesn't produce spurious plans after apply, and imports successfully @@ -541,7 +606,7 @@ func testAccEnsureSuccessExhaustionTimeAlert(t *testing.T, burnAlert *client.Bur resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "description", testBADescription), resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "alert_type", "exhaustion_time"), resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "exhaustion_minutes", fmt.Sprintf("%d", exhaustionMinutes)), - resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.#", "1"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.#", "2"), resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.#", "1"), resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.0.pagerduty_severity", pagerdutySeverity), @@ -551,6 +616,31 @@ func testAccEnsureSuccessExhaustionTimeAlert(t *testing.T, burnAlert *client.Bur ) } +// Checks that the exhaustion time burn alert exists, has the correct attributes, and has the correct state +func testAccEnsureSuccessExhaustionTimeAlertWithWebhookRecip(t *testing.T, burnAlert *client.BurnAlert, exhaustionMinutes int, sloID, varValue string) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + // Check that the burn alert exists + testAccEnsureBurnAlertExists(t, "honeycombio_burn_alert.test", burnAlert), + + // Check that the burn alert has the correct attributes + testAccEnsureAttributesCorrectExhaustionTime(burnAlert, exhaustionMinutes, sloID), + + // Check that the burn alert has the correct values in state + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "slo_id", sloID), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "description", testBADescription), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "alert_type", "exhaustion_time"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "exhaustion_minutes", fmt.Sprintf("%d", exhaustionMinutes)), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.#", "1"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.#", "1"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.0.variable.0.name", "severity"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.0.variable.0.value", varValue), + + // Budget rate attributes should not be set + resource.TestCheckNoResourceAttr("honeycombio_burn_alert.test", "budget_rate_window_minutes"), + resource.TestCheckNoResourceAttr("honeycombio_burn_alert.test", "budget_rate_decrease_percent"), + ) +} + // Checks that the budget rate burn alert exists, has the correct attributes, and has the correct state func testAccEnsureSuccessBudgetRateAlert(t *testing.T, burnAlert *client.BurnAlert, budgetRateWindowMinutes int, budgetRateDecreasePercent float64, pagerdutySeverity, sloID string) resource.TestCheckFunc { return resource.ComposeAggregateTestCheckFunc( @@ -574,6 +664,32 @@ func testAccEnsureSuccessBudgetRateAlert(t *testing.T, burnAlert *client.BurnAle ) } +// Checks that the budget rate burn alert exists, has the correct attributes, and has the correct state +func testAccEnsureSuccessBudgetRateAlertWithWebhookRecip(t *testing.T, burnAlert *client.BurnAlert, budgetRateWindowMinutes int, budgetRateDecreasePercent float64, sloID, varValue string) resource.TestCheckFunc { + return resource.ComposeAggregateTestCheckFunc( + // Check that the burn alert exists + testAccEnsureBurnAlertExists(t, "honeycombio_burn_alert.test", burnAlert), + + // Check that the burn alert has the correct attributes + testAccEnsureAttributesCorrectBudgetRate(burnAlert, budgetRateWindowMinutes, budgetRateDecreasePercent, sloID), + + // Check that the burn alert has the correct values in state + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "slo_id", sloID), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "description", testBADescription), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "alert_type", "budget_rate"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "budget_rate_window_minutes", fmt.Sprintf("%d", budgetRateWindowMinutes)), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "budget_rate_decrease_percent", helper.FloatToPercentString(budgetRateDecreasePercent)), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.#", "1"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.#", "1"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.0.variable.#", "1"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.0.variable.0.name", "severity"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.0.variable.0.value", varValue), + + // Exhaustion time attributes should not be set + resource.TestCheckNoResourceAttr("honeycombio_burn_alert.test", "exhaustion_minutes"), + ) +} + func testAccEnsureBurnAlertExists(t *testing.T, name string, burnAlert *client.BurnAlert) resource.TestCheckFunc { return func(s *terraform.State) error { resourceState, ok := s.RootModule().Resources[name] @@ -722,6 +838,13 @@ resource "honeycombio_burn_alert" "test" { } func testAccConfigBurnAlertDefault_basic(exhaustionMinutes int, dataset, sloID, pdseverity string) string { + tmplBody := `< Date: Fri, 20 Dec 2024 10:35:27 -0500 Subject: [PATCH 4/6] adjust test --- internal/provider/burn_alert_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/provider/burn_alert_resource_test.go b/internal/provider/burn_alert_resource_test.go index c7bd4019..92c9fb83 100644 --- a/internal/provider/burn_alert_resource_test.go +++ b/internal/provider/burn_alert_resource_test.go @@ -606,7 +606,7 @@ func testAccEnsureSuccessExhaustionTimeAlert(t *testing.T, burnAlert *client.Bur resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "description", testBADescription), resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "alert_type", "exhaustion_time"), resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "exhaustion_minutes", fmt.Sprintf("%d", exhaustionMinutes)), - resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.#", "2"), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.#", "1"), resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.#", "1"), resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "recipient.0.notification_details.0.pagerduty_severity", pagerdutySeverity), From c211fa78840da081824441df8e0d2751962164eb Mon Sep 17 00:00:00 2001 From: brookesargent Date: Fri, 20 Dec 2024 12:46:01 -0500 Subject: [PATCH 5/6] trigger test --- internal/provider/trigger_resource_test.go | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/internal/provider/trigger_resource_test.go b/internal/provider/trigger_resource_test.go index ae7c072f..66a9552c 100644 --- a/internal/provider/trigger_resource_test.go +++ b/internal/provider/trigger_resource_test.go @@ -78,6 +78,36 @@ func TestAcc_TriggerResource(t *testing.T) { }, }) }) + + t.Run("trigger resource with custom webhook recipient", func(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: testAccPreCheck(t), + ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory, + Steps: []resource.TestStep{ + { + Config: testAccConfigBasicTriggerTestWithWebhookRecip(dataset, name, "info"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccEnsureTriggerExists(t, "honeycombio_trigger.test"), + resource.TestCheckResourceAttr("honeycombio_trigger.test", "name", name), + resource.TestCheckResourceAttr("honeycombio_trigger.test", "frequency", "600"), + resource.TestCheckResourceAttr("honeycombio_trigger.test", "recipient.#", "1"), + resource.TestCheckResourceAttr("honeycombio_trigger.test", "threshold.0.exceeded_limit", "1"), + resource.TestCheckResourceAttrPair("honeycombio_trigger.test", "query_id", "honeycombio_query.test", "id"), + resource.TestCheckNoResourceAttr("honeycombio_trigger.test", "query_json"), + ), + }, + // then update the variable value from info -> critical + { + Config: testAccConfigBasicTriggerTestWithWebhookRecip(dataset, name, "critical"), + }, + { + ResourceName: "honeycombio_trigger.test", + ImportStateIdPrefix: fmt.Sprintf("%v/", dataset), + ImportState: true, + }, + }, + }) + }) } // TestAcc_TriggerResourceUpgradeFromVersion014 is intended to test the migration @@ -839,6 +869,77 @@ resource "honeycombio_trigger" "test" { }`, dataset, name, pdseverity, email, pdKey, pdName) } +func testAccConfigBasicTriggerTestWithWebhookRecip(dataset, name, varValue string) string { + tmplBody := `< Date: Fri, 20 Dec 2024 12:52:16 -0500 Subject: [PATCH 6/6] a little more cleanup --- internal/provider/notification_recipients.go | 2 +- internal/provider/trigger_resource_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/provider/notification_recipients.go b/internal/provider/notification_recipients.go index 1421379b..a74775f0 100644 --- a/internal/provider/notification_recipients.go +++ b/internal/provider/notification_recipients.go @@ -102,7 +102,7 @@ func notificationRecipientSchema(allowedTypes []client.RecipientType) schema.Set }, }, "value": schema.StringAttribute{ - Description: "The variable value", + Description: "The value of the variable", Optional: true, Computed: true, Default: stringdefault.StaticString(""), diff --git a/internal/provider/trigger_resource_test.go b/internal/provider/trigger_resource_test.go index 66a9552c..1f54dbd3 100644 --- a/internal/provider/trigger_resource_test.go +++ b/internal/provider/trigger_resource_test.go @@ -91,6 +91,9 @@ func TestAcc_TriggerResource(t *testing.T) { resource.TestCheckResourceAttr("honeycombio_trigger.test", "name", name), resource.TestCheckResourceAttr("honeycombio_trigger.test", "frequency", "600"), resource.TestCheckResourceAttr("honeycombio_trigger.test", "recipient.#", "1"), + resource.TestCheckResourceAttr("honeycombio_trigger.test", "recipient.0.notification_details.#", "1"), + resource.TestCheckResourceAttr("honeycombio_trigger.test", "recipient.0.notification_details.0.variable.0.name", "severity"), + resource.TestCheckResourceAttr("honeycombio_trigger.test", "recipient.0.notification_details.0.variable.0.value", "info"), resource.TestCheckResourceAttr("honeycombio_trigger.test", "threshold.0.exceeded_limit", "1"), resource.TestCheckResourceAttrPair("honeycombio_trigger.test", "query_id", "honeycombio_query.test", "id"), resource.TestCheckNoResourceAttr("honeycombio_trigger.test", "query_json"),