Skip to content

Commit

Permalink
fix(r/burn_alert): handle existing remote description with default de…
Browse files Browse the repository at this point in the history
…scription 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
  • Loading branch information
jharley authored Nov 15, 2024
1 parent c8084fc commit 292bbb2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/burn_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
48 changes: 47 additions & 1 deletion internal/provider/burn_alert_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 292bbb2

Please sign in to comment.