Skip to content

Commit

Permalink
feat(destinations): expose destination entity guid (#2590)
Browse files Browse the repository at this point in the history
Co-authored-by: pranav-new-relic <[email protected]>
  • Loading branch information
nzur-newrelic and pranav-new-relic authored Mar 5, 2024
1 parent 429cdb9 commit d0eb7c1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions newrelic/data_source_newrelic_notifications_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func dataSourceNewRelicNotificationDestination() *schema.Resource {
ExactlyOneOf: []string{"id", "name"},
Description: "The ID of the destination.",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "Destination entity GUID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
5 changes: 5 additions & 0 deletions newrelic/resource_newrelic_notifications_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func resourceNewRelicNotificationDestination() *schema.Resource {
Computed: true,
Description: "The last time a notification was sent.",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "Destination entity GUID",
},
},
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
Expand Down
2 changes: 2 additions & 0 deletions newrelic/resource_newrelic_notifications_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ func TestNewRelicNotificationDestination_BasicAuth(t *testing.T) {
Config: testNewRelicNotificationDestinationConfig(testAccountID, rName, authAttr),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicNotificationDestinationExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "guid"),
),
},
// Update
{
Config: testNewRelicNotificationDestinationConfig(testAccountID, fmt.Sprintf("%s-updated", rName), authAttr),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicNotificationDestinationExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "guid"),
),
},
// Import
Expand Down
8 changes: 8 additions & 0 deletions newrelic/structures_newrelic_notifications_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func flattenNotificationDestination(destination *notifications.AiNotificationsDe
return err
}

if err := d.Set("guid", destination.GUID); err != nil {
return err
}

auth := flattenNotificationDestinationAuth(destination.Auth, d)

var authAttr string
Expand Down Expand Up @@ -248,5 +252,9 @@ func flattenNotificationDestinationDataSource(destination *notifications.AiNotif
return err
}

if err := d.Set("guid", destination.GUID); err != nil {
return err
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func TestExpandNotificationDestination(t *testing.T) {

func TestFlattenNotificationDestination(t *testing.T) {
r := resourceNewRelicNotificationDestination()
guid := notifications.EntityGUID("testdestinationentityguid")

cases := map[string]struct {
Data map[string]interface{}
Expand All @@ -124,10 +125,12 @@ func TestFlattenNotificationDestination(t *testing.T) {
Data: map[string]interface{}{
"name": "testing123",
"type": "WEBHOOK",
"guid": "testdestinationentityguid",
},
Flattened: &notifications.AiNotificationsDestination{
Name: "testing123",
Type: "WEBHOOK",
GUID: guid,
},
},
}
Expand Down Expand Up @@ -157,6 +160,7 @@ func TestFlattenNotificationDestination(t *testing.T) {

func TestFlattenNotificationDestinationDataSource(t *testing.T) {
r := dataSourceNewRelicNotificationDestination()
guid := notifications.EntityGUID("testdestinationentityguid")

cases := map[string]struct {
Data map[string]interface{}
Expand All @@ -168,10 +172,12 @@ func TestFlattenNotificationDestinationDataSource(t *testing.T) {
Data: map[string]interface{}{
"name": "testing123",
"type": "WEBHOOK",
"guid": "testdestinationentityguid",
},
Flattened: &notifications.AiNotificationsDestination{
Name: "testing123",
Type: "WEBHOOK",
GUID: guid,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/notification_destination.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ In addition to all arguments above, the following attributes are exported:
* `property` - A nested block that describes a notification destination property.
* `active` - An indication whether the notification destination is active or not.
* `status` - The status of the notification destination.
* `guid` - The unique entity identifier of the destination in New Relic.


```
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/notification_destination.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Each notification destination type supports a specific set of arguments for the
In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the destination.
* `guid` - The unique entity identifier of the destination in New Relic.

## Additional Examples

Expand Down

0 comments on commit d0eb7c1

Please sign in to comment.