This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
forked from PagerDuty/terraform-provider-pagerduty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upstream-master' into fork-master
* upstream-master: update test cases for `data.pagerduty_users` add test case for querying with more than one team add `pagerduty_users` data source Update CHANGELOG.md v2.5.2 update to go-version 1.17 Update Changelog for version 2.5.2 remove `expectNonEmptyPlanFromTest` from Service test add `service_dependency` drift detection during deletion add input validation for `service_dependency` type Fix typos in the event orchestration router docs Fix docs for event_orchestration resources import # Conflicts: # .github/workflows/release.yml # .github/workflows/test.yml # .go-version # pagerduty/resource_pagerduty_service.go
- Loading branch information
Showing
13 changed files
with
373 additions
and
16 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,93 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/nordcloud/go-pagerduty/pagerduty" | ||
) | ||
|
||
func dataSourcePagerDutyUsers() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourcePagerDutyUsersRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"team_ids": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"users": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "List of users who are members of the team", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"email": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourcePagerDutyUsersRead(d *schema.ResourceData, meta interface{}) error { | ||
client, err := meta.(*Config).Client() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[INFO] Reading PagerDuty users") | ||
|
||
pre := d.Get("team_ids").([]interface{}) | ||
var teamIds []string | ||
for _, ti := range pre { | ||
teamIds = append(teamIds, ti.(string)) | ||
} | ||
|
||
o := &pagerduty.ListUsersOptions{ | ||
TeamIDs: teamIds, | ||
} | ||
|
||
return resource.Retry(5*time.Minute, func() *resource.RetryError { | ||
resp, err := client.Users.ListAll(o) | ||
if err != nil { | ||
// Delaying retry by 30s as recommended by PagerDuty | ||
// https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit | ||
time.Sleep(30 * time.Second) | ||
return resource.RetryableError(err) | ||
} | ||
|
||
var users []map[string]interface{} | ||
for _, user := range resp { | ||
users = append(users, map[string]interface{}{ | ||
"id": user.ID, | ||
"name": user.Name, | ||
"email": user.Email, | ||
}) | ||
} | ||
|
||
// Since this data doesn't have an unique ID, this force this data to be | ||
// refreshed in every Terraform apply | ||
d.SetId(strconv.FormatInt(time.Now().Unix(), 10)) | ||
d.Set("users", users) | ||
|
||
return nil | ||
}) | ||
} |
Oops, something went wrong.