Skip to content
Closed
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
7 changes: 7 additions & 0 deletions github/data_source_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func dataSourceGithubTeam() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"notification_setting": {
Type: schema.TypeString,
Computed: true,
},
"permission": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -210,6 +214,9 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
if err = d.Set("privacy", team.GetPrivacy()); err != nil {
return err
}
if err = d.Set("notification_setting", team.GetNotificationSetting()); err != nil {
return err
}
if err = d.Set("permission", team.GetPermission()); err != nil {
return err
}
Expand Down
54 changes: 54 additions & 0 deletions github/data_source_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,60 @@ func TestAccGithubTeamDataSource(t *testing.T) {

})

t.Run("queries teams with notification settings", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_team" "test_enabled" {
name = "tf-acc-test-enabled-%s"
notification_setting = "notifications_enabled"
}

resource "github_team" "test_disabled" {
name = "tf-acc-test-disabled-%s"
notification_setting = "notifications_disabled"
}

data "github_team" "test_enabled" {
slug = github_team.test_enabled.slug
}

data "github_team" "test_disabled" {
slug = github_team.test_disabled.slug
}
`, randomID, randomID)

check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.github_team.test_enabled", "notification_setting", "notifications_enabled"),
resource.TestCheckResourceAttr("data.github_team.test_disabled", "notification_setting", "notifications_disabled"),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})

t.Run("queries an existing team with connected repositories", func(t *testing.T) {

config := fmt.Sprintf(`
Expand Down
24 changes: 18 additions & 6 deletions github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ func resourceGithubTeam() *schema.Resource {
Description: "The level of privacy for the team. Must be one of 'secret' or 'closed'.",
ValidateDiagFunc: validateValueFunc([]string{"secret", "closed"}),
},
"notification_setting": {
Type: schema.TypeString,
Optional: true,
Default: "notifications_enabled",
Description: "The notification setting for the team. Must be one of 'notifications_enabled' or 'notifications_disabled'.",
ValidateDiagFunc: validateValueFunc([]string{"notifications_enabled", "notifications_disabled"}),
},
"parent_team_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -115,9 +122,10 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)

newTeam := github.NewTeam{
Name: name,
Description: github.String(d.Get("description").(string)),
Privacy: github.String(d.Get("privacy").(string)),
Name: name,
Description: github.String(d.Get("description").(string)),
Privacy: github.String(d.Get("privacy").(string)),
NotificationSetting: github.String(d.Get("notification_setting").(string)),
}

if ldapDN := d.Get("ldap_dn").(string); ldapDN != "" {
Expand Down Expand Up @@ -222,6 +230,9 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
if err = d.Set("privacy", team.GetPrivacy()); err != nil {
return err
}
if err = d.Set("notification_setting", team.GetNotificationSetting()); err != nil {
return err
}
if parent := team.Parent; parent != nil {
if err = d.Set("parent_team_id", strconv.FormatInt(team.Parent.GetID(), 10)); err != nil {
return err
Expand Down Expand Up @@ -270,9 +281,10 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
var removeParentTeam bool

editedTeam := github.NewTeam{
Name: d.Get("name").(string),
Description: github.String(d.Get("description").(string)),
Privacy: github.String(d.Get("privacy").(string)),
Name: d.Get("name").(string),
Description: github.String(d.Get("description").(string)),
Privacy: github.String(d.Get("privacy").(string)),
NotificationSetting: github.String(d.Get("notification_setting").(string)),
}
if parentTeamID, ok := d.GetOk("parent_team_id"); ok {
teamId, err := getTeamID(parentTeamID.(string), meta)
Expand Down
77 changes: 77 additions & 0 deletions github/resource_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,83 @@ func TestAccGithubTeamRemovesDefaultMaintainer(t *testing.T) {

}

func TestAccGithubTeamNotificationSetting(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

t.Run("creates teams with different notification settings", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_team" "test_default" {
name = "tf-acc-default-%s"
}

resource "github_team" "test_enabled" {
name = "tf-acc-enabled-%s"
notification_setting = "notifications_enabled"
}

resource "github_team" "test_disabled" {
name = "tf-acc-disabled-%s"
notification_setting = "notifications_disabled"
}
`, randomID, randomID, randomID)

configUpdated := fmt.Sprintf(`
resource "github_team" "test_default" {
name = "tf-acc-default-%s"
}

resource "github_team" "test_enabled" {
name = "tf-acc-enabled-%s"
notification_setting = "notifications_disabled"
}

resource "github_team" "test_disabled" {
name = "tf-acc-disabled-%s"
notification_setting = "notifications_enabled"
}
`, randomID, randomID, randomID)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_team.test_default", "notification_setting", "notifications_enabled"),
resource.TestCheckResourceAttr("github_team.test_enabled", "notification_setting", "notifications_enabled"),
resource.TestCheckResourceAttr("github_team.test_disabled", "notification_setting", "notifications_disabled"),
),
},
{
Config: configUpdated,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_team.test_default", "notification_setting", "notifications_enabled"),
resource.TestCheckResourceAttr("github_team.test_enabled", "notification_setting", "notifications_disabled"),
resource.TestCheckResourceAttr("github_team.test_disabled", "notification_setting", "notifications_enabled"),
),
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})
}

func TestAccGithubTeamUpdateName(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

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 @@ -31,6 +31,7 @@ data "github_team" "example" {
* `name` - the team's full name.
* `description` - the team's description.
* `privacy` - the team's privacy type.
* `notification_setting` - the team's notification setting.
* `permission` - the team's permission level.
* `members` - List of team members (list of GitHub usernames). Not returned if `summary_only = true`
* `repositories` - List of team repositories (list of repo names). Not returned if `summary_only = true`
Expand Down
9 changes: 6 additions & 3 deletions website/docs/r/team.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ a new team will be created. When destroyed, that team will be removed.
```hcl
# Add a team to the organization
resource "github_team" "some_team" {
name = "some-team"
description = "Some cool team"
privacy = "closed"
name = "some-team"
description = "Some cool team"
privacy = "closed"
notification_setting = "notifications_enabled"
}
```

Expand All @@ -31,6 +32,8 @@ The following arguments are supported:
* `description` - (Optional) A description of the team.
* `privacy` - (Optional) The level of privacy for the team. Must be one of `secret` or `closed`.
Defaults to `secret`.
* `notification_setting` - (Optional) The notification setting for the team. Must be one of `notifications_enabled` or `notifications_disabled`.
Defaults to `notifications_disabled`
* `parent_team_id` - (Optional) The ID or slug of the parent team, if this is a nested team.
* `ldap_dn` - (Optional) The LDAP Distinguished Name of the group where membership will be synchronized. Only available in GitHub Enterprise Server.
* `create_default_maintainer` - (Optional) Adds a default maintainer to the team. Defaults to `false` and adds the creating user to the team when `true`.
Expand Down