Skip to content

Commit

Permalink
alert_contact: allow data retrieval by either friendly_name or value
Browse files Browse the repository at this point in the history
  • Loading branch information
gxben committed Oct 2, 2024
1 parent fcffc28 commit 83904e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/provider/data_source_uptimerobot_alert_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func dataSourceAlertContactRead(d *schema.ResourceData, m interface{}) error {
}

friendlyName := d.Get("friendly_name").(string)
value := d.Get("value").(string)

var alertContact uptimerobotapi.AlertContact

Expand All @@ -35,9 +36,13 @@ func dataSourceAlertContactRead(d *schema.ResourceData, m interface{}) error {
alertContact = a
break
}
if value != "" && a.Value == value {
alertContact = a
break
}
}
if alertContact == (uptimerobotapi.AlertContact{}) {
return fmt.Errorf("failed to find alert contact by name %s", friendlyName)
return fmt.Errorf("failed to find alert contact by either name ('%s') or value ('%s')", friendlyName, value)
}

d.SetId(alertContact.ID)
Expand Down

0 comments on commit 83904e5

Please sign in to comment.