From 292bbb2669b9d3acc8ee540539af1fbb478916bd Mon Sep 17 00:00:00 2001 From: Jason Harley Date: Fri, 15 Nov 2024 15:22:01 -0500 Subject: [PATCH] fix(r/burn_alert): handle existing remote description with default description value (#575) When upgrading to 0.28.0, if you have an existing burn alert that had a description set (via the UI, most likely) but the description was yet to be added to HCL config you will get the following error: ``` Error: Provider produced inconsistent result after apply When applying changes to honeycombio_burn_alert.test, provider "provider[\"registry.terraform.io/hashicorp/honeycombio\"]" produced an unexpected new value: .description: was cty.StringVal(""), but now cty.StringVal("test description"). ``` Fix is to ensure we send the empty string when we marshal our JSON --- client/burn_alert.go | 2 +- internal/provider/burn_alert_resource_test.go | 48 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/client/burn_alert.go b/client/burn_alert.go index 78789afd..2d86351e 100644 --- a/client/burn_alert.go +++ b/client/burn_alert.go @@ -46,7 +46,7 @@ type BurnAlert struct { ExhaustionMinutes *int `json:"exhaustion_minutes,omitempty"` BudgetRateWindowMinutes *int `json:"budget_rate_window_minutes,omitempty"` BudgetRateDecreaseThresholdPerMillion *int `json:"budget_rate_decrease_threshold_per_million,omitempty"` - Description string `json:"description,omitempty"` + Description string `json:"description"` SLO SLORef `json:"slo"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` diff --git a/internal/provider/burn_alert_resource_test.go b/internal/provider/burn_alert_resource_test.go index 3a6db488..ba3ab4f7 100644 --- a/internal/provider/burn_alert_resource_test.go +++ b/internal/provider/burn_alert_resource_test.go @@ -482,6 +482,52 @@ func TestAcc_BurnAlertResource_HandlesDynamicRecipientBlock(t *testing.T) { }) } +func TestAcc_BurnAlertResource_HandlesDescriptionSetToEmptyString(t *testing.T) { + ctx := context.Background() + dataset, sloID := burnAlertAccTestSetup(t) + burnAlert := &client.BurnAlert{} + + config := fmt.Sprintf(` +resource "honeycombio_burn_alert" "test" { + exhaustion_minutes = 240 + + dataset = "%s" + slo_id = "%s" + + recipient { + type = "email" + target = "%s" + } +}`, dataset, sloID, test.RandomEmail()) + + resource.Test(t, resource.TestCase{ + PreCheck: testAccPreCheck(t), + ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testAccEnsureBurnAlertExists(t, "honeycombio_burn_alert.test", burnAlert), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "description", ""), + ), + }, + { + PreConfig: func() { + // add a description to the burn alert outside of Terraform + burnAlert.Description = "test description" + _, err := testAccClient(t).BurnAlerts.Update(ctx, dataset, burnAlert) + require.NoError(t, err, "failed to update burn alert") + }, + Config: config, + Check: resource.ComposeTestCheckFunc( + testAccEnsureBurnAlertExists(t, "honeycombio_burn_alert.test", burnAlert), + resource.TestCheckResourceAttr("honeycombio_burn_alert.test", "description", ""), + ), + }, + }, + }) +} + // Checks that the exhaustion time burn alert exists, has the correct attributes, and has the correct state func testAccEnsureSuccessExhaustionTimeAlert(t *testing.T, burnAlert *client.BurnAlert, exhaustionMinutes int, pagerdutySeverity, sloID string) resource.TestCheckFunc { return resource.ComposeAggregateTestCheckFunc( @@ -529,7 +575,7 @@ func testAccEnsureSuccessBudgetRateAlert(t *testing.T, burnAlert *client.BurnAle ) } -func testAccEnsureBurnAlertExists(t *testing.T, name string, burnAlert *client.BurnAlert) resource.TestCheckFunc { +func testAccEnsureBurnAlertExists(t *testing.T, name string, burnAlert *client.BurnAlert) resource.TestCheckFunc { //nolint:unparam return func(s *terraform.State) error { resourceState, ok := s.RootModule().Resources[name] if !ok {