This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow default alert contact to be configured
- Loading branch information
Johan Bloemberg
committed
Apr 3, 2019
1 parent
8281146
commit 5ddb18c
Showing
4 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package uptimerobot | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/louy/terraform-provider-uptimerobot/uptimerobot/api" | ||
) | ||
|
||
func dataSourceAlertContact() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAlertContactRead, | ||
Schema: map[string]*schema.Schema{ | ||
"friendly_name": {Required: true, Type: schema.TypeString}, | ||
"type": {Computed: true, Type: schema.TypeString}, | ||
"status": {Computed: true, Type: schema.TypeString}, | ||
"value": {Computed: true, Type: schema.TypeString}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAlertContactRead(d *schema.ResourceData, m interface{}) error { | ||
alertContacts, err := m.(uptimerobotapi.UptimeRobotApiClient).GetAlertContacts() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
friendlyName := d.Get("friendly_name").(string) | ||
|
||
var alertContact uptimerobotapi.AlertContact | ||
|
||
for _, a := range alertContacts { | ||
if a.FriendlyName == friendlyName { | ||
alertContact = a | ||
break | ||
} | ||
} | ||
if alertContact == (uptimerobotapi.AlertContact{}) { | ||
return fmt.Errorf("Failed to find alert contact with name %s", friendlyName) | ||
} | ||
|
||
d.Set("friendly_name", alertContact.FriendlyName) | ||
d.Set("type", alertContact.Type) | ||
d.Set("status", alertContact.Status) | ||
d.Set("value", alertContact.Value) | ||
|
||
return nil | ||
} |
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