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

teams: add support for private teams #612

Merged
merged 4 commits into from
Oct 25, 2023
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/hashicorp/terraform-exec v0.16.0
github.com/hashicorp/terraform-json v0.13.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.11.0
github.com/heimweh/go-pagerduty v0.0.0-20230908205257-a96e6c05f7ea
github.com/heimweh/go-pagerduty v0.0.0-20231025174125-1492ec59406f
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/heimweh/go-pagerduty v0.0.0-20230908205257-a96e6c05f7ea h1:8SGdS666zcEi1jY34UmJXNXkRD+w2ebQhc5/ok8cY2k=
github.com/heimweh/go-pagerduty v0.0.0-20230908205257-a96e6c05f7ea/go.mod h1:r59w5iyN01Qvi734yA5hZldbSeJJmsJzee/1kQ/MK7s=
github.com/heimweh/go-pagerduty v0.0.0-20231025174125-1492ec59406f h1:aKlHoRz5VjwQbc5aH8hIMMmdXZIYEJvyIw3DAiHPolc=
github.com/heimweh/go-pagerduty v0.0.0-20231025174125-1492ec59406f/go.mod h1:r59w5iyN01Qvi734yA5hZldbSeJJmsJzee/1kQ/MK7s=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
5 changes: 5 additions & 0 deletions pagerduty/data_source_pagerduty_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func dataSourcePagerDutyTeam() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"default_role": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -79,6 +83,7 @@ func dataSourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error
d.Set("name", found.Name)
d.Set("description", found.Description)
d.Set("parent", found.Parent)
d.Set("default_role", found.DefaultRole)

return nil
})
Expand Down
9 changes: 9 additions & 0 deletions pagerduty/resource_pagerduty_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func resourcePagerDutyTeam() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"default_role": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
Expand All @@ -55,6 +60,9 @@ func buildTeamStruct(d *schema.ResourceData) *pagerduty.Team {
Type: "team_reference",
}
}
if attr, ok := d.GetOk("default_role"); ok {
team.DefaultRole = attr.(string)
}
return team
}

Expand Down Expand Up @@ -115,6 +123,7 @@ func resourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error {
d.Set("name", team.Name)
d.Set("description", team.Description)
d.Set("html_url", team.HTMLURL)
d.Set("default_role", team.DefaultRole)
}
return nil
})
Expand Down
44 changes: 44 additions & 0 deletions pagerduty/resource_pagerduty_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,39 @@ func TestAccPagerDutyTeam_Basic(t *testing.T) {
})
}

func TestAccPagerDutyTeam_DefaultRole(t *testing.T) {
team := fmt.Sprintf("tf-%s", acctest.RandString(5))
defaultRole := "manager"
defaultRoleUpdated := "none"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyTeamDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyTeamDefaultRoleConfig(team, defaultRole),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyTeamExists("pagerduty_team.foo"),
resource.TestCheckResourceAttr(
"pagerduty_team.foo", "name", team),
resource.TestCheckResourceAttr(
"pagerduty_team.foo", "default_role", defaultRole),
resource.TestCheckResourceAttrSet(
"pagerduty_team.foo", "html_url"),
),
},
{
Config: testAccCheckPagerDutyTeamDefaultRoleConfig(team, defaultRoleUpdated),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"pagerduty_team.foo", "default_role", defaultRoleUpdated),
),
},
},
})
}

func TestAccPagerDutyTeam_Parent(t *testing.T) {
team := fmt.Sprintf("tf-%s", acctest.RandString(5))
parent := fmt.Sprintf("tf-%s", acctest.RandString(5))
Expand Down Expand Up @@ -179,6 +212,17 @@ resource "pagerduty_team" "foo" {
}`, team)
}

func testAccCheckPagerDutyTeamDefaultRoleConfig(team, defaultRole string) string {
return fmt.Sprintf(`

resource "pagerduty_team" "foo" {
name = "%s"
description = "foo"
default_role = "%s"
}
`, team, defaultRole)
}

func testAccCheckPagerDutyTeamWithParentConfig(team, parent string) string {
return fmt.Sprintf(`
resource "pagerduty_team" "parent" {
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/heimweh/go-pagerduty/pagerduty/team.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ github.com/hashicorp/terraform-svchost
# github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
## explicit
github.com/hashicorp/yamux
# github.com/heimweh/go-pagerduty v0.0.0-20230908205257-a96e6c05f7ea
# github.com/heimweh/go-pagerduty v0.0.0-20231025174125-1492ec59406f
## explicit; go 1.17
github.com/heimweh/go-pagerduty/pagerduty
github.com/heimweh/go-pagerduty/persistentconfig
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/team.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ The following arguments are supported:
* `name` - The name of the found team.
* `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.
* `default_role` - (Optional) The team is private if the value is "none", or public if it is "manager" (the default permissions for a non-member of the team are either "none", or their base role up until "manager").

[1]: https://developer.pagerduty.com/api-reference/b3A6Mjc0ODIyMw-list-teams
1 change: 1 addition & 0 deletions website/docs/r/team.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following arguments are supported:
* `description` - (Optional) A human-friendly description of the team.
If not set, a placeholder of "Managed by Terraform" will be set.
* `parent` - (Optional) ID of the parent team. This is available to accounts with the Team Hierarchy feature enabled. Please contact your account manager for more information.
* `default_role` - (Optional) The team is private if the value is "none", or public if it is "manager" (the default permissions for a non-member of the team are either "none", or their base role up until "manager").

## Attributes Reference

Expand Down
Loading