Skip to content

Commit

Permalink
Update notifications on fabric connections resource
Browse files Browse the repository at this point in the history
  • Loading branch information
thogarty committed Jan 7, 2025
1 parent 673e6d8 commit f696acc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/resources/fabric/connection/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
"reflect"
"sort"
)

func additionalInfoContainsAWSSecrets(info []interface{}) ([]interface{}, bool) {
Expand Down Expand Up @@ -658,6 +660,19 @@ func getUpdateRequests(conn *fabricv4.Connection, d *schema.ResourceData) ([][]f

awsSecrets, hasAWSSecrets := additionalInfoContainsAWSSecrets(additionalInfo)

existingNotifications := conn.GetNotifications()
schemaNotifications := d.Get("notifications").([]interface{})
updateNotificationsVal := equinix_fabric_schema.NotificationsTerraformToGo(schemaNotifications)
prevEmails, nextEmails := make([]string, len(existingNotifications[0].GetEmails())), make([]string, len(updateNotificationsVal[0].GetEmails()))
copy(prevEmails, existingNotifications[0].GetEmails())
copy(nextEmails, updateNotificationsVal[0].GetEmails())
sort.Strings(prevEmails)
sort.Strings(nextEmails)

notificationsNeedsUpdate := len(updateNotificationsVal) > len(existingNotifications) ||
string(existingNotifications[0].GetType()) != string(updateNotificationsVal[0].GetType()) ||
!reflect.DeepEqual(prevEmails, nextEmails)

if existingName != updateNameVal {
changeOps = append(changeOps, []fabricv4.ConnectionChangeOperation{
{
Expand Down Expand Up @@ -688,6 +703,16 @@ func getUpdateRequests(conn *fabricv4.Connection, d *schema.ResourceData) ([][]f
})
}

if notificationsNeedsUpdate {
changeOps = append(changeOps, []fabricv4.ConnectionChangeOperation{
{
Op: "replace",
Path: "/notifications",
Value: updateNotificationsVal,
},
})
}

if len(changeOps) == 0 {
return changeOps, fmt.Errorf("nothing to update for the connection %s", existingName)
}
Expand Down

0 comments on commit f696acc

Please sign in to comment.