diff --git a/builtin/providers/github/resource_github_membership.go b/builtin/providers/github/resource_github_membership.go index 2c0ec27f2f9e..8be520f98476 100644 --- a/builtin/providers/github/resource_github_membership.go +++ b/builtin/providers/github/resource_github_membership.go @@ -22,7 +22,7 @@ func resourceGithubMembership() *schema.Resource { "role": &schema.Schema{ Type: schema.TypeString, Optional: true, - ValidateFunc: validateRoleValueFunc([]string{"member", "admin"}), + ValidateFunc: validateValueFunc([]string{"member", "admin"}), Default: "member", }, }, diff --git a/builtin/providers/github/resource_github_team.go b/builtin/providers/github/resource_github_team.go index b38f8d2564df..77c4fdbe6789 100644 --- a/builtin/providers/github/resource_github_team.go +++ b/builtin/providers/github/resource_github_team.go @@ -22,6 +22,12 @@ func resourceGithubTeam() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "privacy": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Default: "secret", + ValidateFunc: validateValueFunc([]string{"secret", "closed"}), + }, }, } } @@ -30,9 +36,11 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*Organization).client n := d.Get("name").(string) desc := d.Get("description").(string) + p := d.Get("privacy").(string) githubTeam, _, err := client.Organizations.CreateTeam(meta.(*Organization).name, &github.Team{ Name: &n, Description: &desc, + Privacy: &p, }) if err != nil { return err @@ -51,6 +59,7 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error { } d.Set("description", team.Description) d.Set("name", team.Name) + d.Set("privacy", team.Privacy) return nil } @@ -65,8 +74,10 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error { name := d.Get("name").(string) description := d.Get("description").(string) + privacy := d.Get("privacy").(string) team.Description = &description team.Name = &name + team.Privacy = &privacy team, _, err = client.Organizations.EditTeam(*team.ID, team) if err != nil { diff --git a/builtin/providers/github/resource_github_team_membership.go b/builtin/providers/github/resource_github_team_membership.go index 6dadfc6f50a0..3bd99cbc8da3 100644 --- a/builtin/providers/github/resource_github_team_membership.go +++ b/builtin/providers/github/resource_github_team_membership.go @@ -31,7 +31,7 @@ func resourceGithubTeamMembership() *schema.Resource { Optional: true, ForceNew: true, Default: "member", - ValidateFunc: validateRoleValueFunc([]string{"member", "maintainer"}), + ValidateFunc: validateValueFunc([]string{"member", "maintainer"}), }, }, } diff --git a/builtin/providers/github/resource_github_team_repository.go b/builtin/providers/github/resource_github_team_repository.go index d4ef1ed08669..cc46f66ce86e 100644 --- a/builtin/providers/github/resource_github_team_repository.go +++ b/builtin/providers/github/resource_github_team_repository.go @@ -33,7 +33,7 @@ func resourceGithubTeamRepository() *schema.Resource { Type: schema.TypeString, Optional: true, Default: "pull", - ValidateFunc: validateRoleValueFunc([]string{"pull", "push", "admin"}), + ValidateFunc: validateValueFunc([]string{"pull", "push", "admin"}), }, }, } diff --git a/builtin/providers/github/resource_github_team_test.go b/builtin/providers/github/resource_github_team_test.go index e5429fe632b6..19b58b18c0cf 100644 --- a/builtin/providers/github/resource_github_team_test.go +++ b/builtin/providers/github/resource_github_team_test.go @@ -97,6 +97,7 @@ const testAccGithubTeamConfig = ` resource "github_team" "foo" { name = "foo" description = "Terraform acc test group" + privacy = "secret" } ` @@ -104,5 +105,6 @@ const testAccGithubTeamUpdateConfig = ` resource "github_team" "foo" { name = "foo2" description = "Terraform acc test group - updated" + privacy = "closed" } ` diff --git a/builtin/providers/github/util.go b/builtin/providers/github/util.go index 3f5e2074a6e4..96256a054515 100644 --- a/builtin/providers/github/util.go +++ b/builtin/providers/github/util.go @@ -17,11 +17,11 @@ func fromGithubID(id *int) string { return strconv.Itoa(*id) } -func validateRoleValueFunc(roles []string) schema.SchemaValidateFunc { +func validateValueFunc(values []string) schema.SchemaValidateFunc { return func(v interface{}, k string) (we []string, errors []error) { value := v.(string) valid := false - for _, role := range roles { + for _, role := range values { if value == role { valid = true break @@ -29,7 +29,7 @@ func validateRoleValueFunc(roles []string) schema.SchemaValidateFunc { } if !valid { - errors = append(errors, fmt.Errorf("%s is an invalid Github role type for %s", value, k)) + errors = append(errors, fmt.Errorf("%s is an invalid value for argument %s", value, k)) } return } diff --git a/builtin/providers/github/util_test.go b/builtin/providers/github/util_test.go index 9efd81f7369f..5d58407ca88a 100644 --- a/builtin/providers/github/util_test.go +++ b/builtin/providers/github/util_test.go @@ -23,13 +23,13 @@ func TestAccGithubUtilRole_validation(t *testing.T) { }, } - validationFunc := validateRoleValueFunc([]string{"valid_one", "valid_two"}) + validationFunc := validateValueFunc([]string{"valid_one", "valid_two"}) for _, tc := range cases { - _, errors := validationFunc(tc.Value, "github_membership") + _, errors := validationFunc(tc.Value, "test_arg") if len(errors) != tc.ErrCount { - t.Fatalf("Expected github_membership to trigger a validation error") + t.Fatalf("Expected 1 validation error") } } } diff --git a/website/source/docs/providers/github/r/team.html.markdown b/website/source/docs/providers/github/r/team.html.markdown index 4e4ee13dd4dd..72eabc3274f6 100644 --- a/website/source/docs/providers/github/r/team.html.markdown +++ b/website/source/docs/providers/github/r/team.html.markdown @@ -20,6 +20,7 @@ a new team will be created. When destroyed, that team will be removed. resource "github_team" "some_team" { name = "some-team" description = "Some cool team" + privacy = "closed" } ``` @@ -29,6 +30,8 @@ The following arguments are supported: * `name` - (Required) The name of the team. * `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`. ## Attributes Reference