Skip to content

Commit

Permalink
Merge pull request #612 from lomkju/add_support_for_private_teams
Browse files Browse the repository at this point in the history
teams: add support for private teams
  • Loading branch information
imjaroiswebdev authored Oct 25, 2023
2 parents 94e7918 + 5e15bab commit ac80658
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 4 deletions.
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

0 comments on commit ac80658

Please sign in to comment.