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

Adding privacy argument for GitHub teams for #6015 #6116

Merged
merged 1 commit into from
Apr 11, 2016
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 builtin/providers/github/resource_github_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand Down
11 changes: 11 additions & 0 deletions builtin/providers/github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
},
},
}
}
Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func resourceGithubTeamMembership() *schema.Resource {
Optional: true,
ForceNew: true,
Default: "member",
ValidateFunc: validateRoleValueFunc([]string{"member", "maintainer"}),
ValidateFunc: validateValueFunc([]string{"member", "maintainer"}),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions builtin/providers/github/resource_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ const testAccGithubTeamConfig = `
resource "github_team" "foo" {
name = "foo"
description = "Terraform acc test group"
privacy = "secret"
}
`

const testAccGithubTeamUpdateConfig = `
resource "github_team" "foo" {
name = "foo2"
description = "Terraform acc test group - updated"
privacy = "closed"
}
`
6 changes: 3 additions & 3 deletions builtin/providers/github/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ 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
}
}

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
}
Expand Down
6 changes: 3 additions & 3 deletions builtin/providers/github/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions website/source/docs/providers/github/r/team.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

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

Expand Down