-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better handle the case where a recipient is modified outside of …
…Terraform (#433) If a recipient used by a Trigger or Burn Alert was updated outside of Terraform (i.e. the UI or via the API in some other way) the provider would get rather cranky and spit out an error like: > Could not find Recipient xysef83ryH in state This adjusts that behaviour to instead accept that the recipient is defined remotely and allow the rest of Terraform's diffing process to handle the difference and present that plan to the user. Effects `r/burn_alert` and `r/trigger` Co-authored-by: Dean Strelau <[email protected]>
- Loading branch information
Showing
6 changed files
with
311 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package provider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/honeycombio/terraform-provider-honeycombio/client" | ||
"github.com/honeycombio/terraform-provider-honeycombio/internal/models" | ||
) | ||
|
||
func Test_reconcileReadNotificationRecipientState(t *testing.T) { | ||
type args struct { | ||
remote []client.NotificationRecipient | ||
state []models.NotificationRecipientModel | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []models.NotificationRecipientModel | ||
}{ | ||
{ | ||
name: "both empty", | ||
args: args{}, | ||
want: []models.NotificationRecipientModel{}, | ||
}, | ||
{ | ||
name: "empty state", | ||
args: args{ | ||
remote: []client.NotificationRecipient{ | ||
{ID: "abcd12345", Type: client.RecipientTypeEmail, Target: "[email protected]"}, | ||
}, | ||
state: []models.NotificationRecipientModel{}, | ||
}, | ||
want: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("abcd12345"), Type: types.StringValue("email"), Target: types.StringValue("[email protected]")}, | ||
}, | ||
}, | ||
{ | ||
name: "empty remote", | ||
args: args{ | ||
remote: []client.NotificationRecipient{}, | ||
state: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("abcd12345"), Type: types.StringValue("email"), Target: types.StringValue("[email protected]")}, | ||
}, | ||
}, | ||
want: []models.NotificationRecipientModel{}, | ||
}, | ||
{ | ||
name: "remote and state reconciled", | ||
args: args{ | ||
remote: []client.NotificationRecipient{ | ||
{ID: "abcd12345", Type: client.RecipientTypeEmail, Target: "[email protected]"}, | ||
{ID: "efgh67890", Type: client.RecipientTypeSlack, Target: "#test-channel"}, | ||
}, | ||
state: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("abcd12345")}, // defined by ID | ||
{Type: types.StringValue("slack"), Target: types.StringValue("#test-channel")}, // defined by type+target | ||
}, | ||
}, | ||
want: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("abcd12345")}, | ||
{Type: types.StringValue("slack"), Target: types.StringValue("#test-channel")}, | ||
}, | ||
}, | ||
{ | ||
name: "remote has additional recipients", | ||
args: args{ | ||
remote: []client.NotificationRecipient{ | ||
{ID: "abcd12345", Type: client.RecipientTypeEmail, Target: "[email protected]"}, | ||
{ID: "efgh67890", Type: client.RecipientTypeSlack, Target: "#test-channel"}, | ||
{ID: "qrsty3847", Type: client.RecipientTypeSlack, Target: "#test-alerts"}, | ||
{ | ||
ID: "ijkl13579", | ||
Type: client.RecipientTypePagerDuty, | ||
Target: "test-pagerduty", | ||
Details: &client.NotificationRecipientDetails{ | ||
PDSeverity: client.PDSeverityWARNING, | ||
}}, | ||
}, | ||
state: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("abcd12345")}, // defined by ID | ||
{Type: types.StringValue("slack"), Target: types.StringValue("#test-channel")}, // defined by type+target | ||
}, | ||
}, | ||
want: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("abcd12345")}, | ||
{Type: types.StringValue("slack"), Target: types.StringValue("#test-channel")}, | ||
{ID: types.StringValue("qrsty3847"), Type: types.StringValue("slack"), Target: types.StringValue("#test-alerts")}, | ||
{ | ||
ID: types.StringValue("ijkl13579"), | ||
Type: types.StringValue("pagerduty"), | ||
Target: types.StringValue("test-pagerduty"), | ||
Details: []models.NotificationRecipientDetailsModel{ | ||
{PDSeverity: types.StringValue("warning")}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "state has additional recipients", | ||
args: args{ | ||
remote: []client.NotificationRecipient{ | ||
{ID: "efgh67890", Type: client.RecipientTypeSlack, Target: "#test-foo"}, | ||
}, | ||
state: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("abcd12345")}, | ||
{Type: types.StringValue("slack"), Target: types.StringValue("#test-foo")}, | ||
{ID: types.StringValue("ijkl13579"), Details: []models.NotificationRecipientDetailsModel{{PDSeverity: types.StringValue("warning")}}}, | ||
}, | ||
}, | ||
want: []models.NotificationRecipientModel{ | ||
{Type: types.StringValue("slack"), Target: types.StringValue("#test-foo")}, | ||
}, | ||
}, | ||
{ | ||
name: "state has totally unmatched recipients", | ||
args: args{ | ||
remote: []client.NotificationRecipient{ | ||
{ID: "efgh67890", Type: client.RecipientTypeSlack, Target: "#test-foo"}, | ||
}, | ||
state: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("abcd12345")}, | ||
{Type: types.StringValue("slack"), Target: types.StringValue("#test-channel")}, | ||
{ID: types.StringValue("ijkl13579"), Details: []models.NotificationRecipientDetailsModel{{PDSeverity: types.StringValue("warning")}}}, | ||
}, | ||
}, | ||
want: []models.NotificationRecipientModel{ | ||
{ID: types.StringValue("efgh67890"), Type: types.StringValue("slack"), Target: types.StringValue("#test-foo")}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.want, reconcileReadNotificationRecipientState(tt.args.remote, tt.args.state)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.