Adding privacy argument for GitHub teams for #6015 (#6116)

Added the ability to set the "privacy" of a github_team resource so all teams won't automatically set to private.

* Added the privacy argument to github_team

* Refactored parameter validation to be general for any argument

* Updated testing
This commit is contained in:
Jacob Severson 2016-04-11 07:09:25 -05:00 committed by Paul Stack
parent 9a315bb83f
commit 7721348b0b
8 changed files with 25 additions and 9 deletions

View File

@ -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",
},
},

View File

@ -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 {

View File

@ -31,7 +31,7 @@ func resourceGithubTeamMembership() *schema.Resource {
Optional: true,
ForceNew: true,
Default: "member",
ValidateFunc: validateRoleValueFunc([]string{"member", "maintainer"}),
ValidateFunc: validateValueFunc([]string{"member", "maintainer"}),
},
},
}

View File

@ -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"}),
},
},
}

View File

@ -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"
}
`

View File

@ -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
}

View File

@ -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")
}
}
}

View File

@ -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