Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a list of users for pagerduty_team #346

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions pagerduty/data_source_pagerduty_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ func dataSourcePagerDutyTeam() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"members": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -71,6 +83,25 @@ func dataSourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error
)
}

if found != nil {
mo := &pagerduty.GetMembersOptions{}
resp, _, err := client.Teams.GetMembers(searchTeam, mo)
if err != nil {
if isErrCode(err, 429) {
// 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)
}

return resource.NonRetryableError(err)
}

if err := d.Set("members", dataSourceMembersRead(resp.Members)); err != nil {
return resource.RetryableError(err)
}
}

d.SetId(found.ID)
d.Set("name", found.Name)
d.Set("description", found.Description)
Expand All @@ -79,3 +110,13 @@ func dataSourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error
return nil
})
}

func dataSourceMembersRead(m []*pagerduty.Member) []map[string]interface{} {
members := make([]map[string]interface{}, 0, len(m))
for _, i := range m {
m := make(map[string]interface{})
m["id"] = i.User.ID
members = append(members, m)
}
return members
}
4 changes: 4 additions & 0 deletions website/docs/d/team.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ The following arguments are supported:
* `description` - A description of the found team.
* `parent` - ID of the parent team. This is available to accounts with the Team Hierarchy feature enabled. Please contact your account manager for more information.

`members`

* `id` - The ID specifying the PagerDuty user.

[1]: https://v1.developer.pagerduty.com/documentation/rest/teams/list