Skip to content

Commit ddd963c

Browse files
authored
Merge pull request #181 from terraform-providers/paultyng/blocks
Add github_organization_block resource, update github SDK, add 0.12 support, fix some other issues.
2 parents 37872b2 + 1c207f8 commit ddd963c

File tree

1,362 files changed

+143728
-41997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,362 files changed

+143728
-41997
lines changed

github/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77
"net/url"
88

9-
"github.com/google/go-github/github"
9+
"github.com/google/go-github/v25/github"
1010
"github.com/hashicorp/terraform/helper/logging"
1111
"golang.org/x/oauth2"
1212
)

github/data_source_github_repositories.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"log"
66

7-
"github.com/google/go-github/github"
7+
"github.com/google/go-github/v25/github"
88
"github.com/hashicorp/terraform/helper/schema"
99
)
1010

github/data_source_github_team.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"strconv"
88

9-
"github.com/google/go-github/github"
9+
"github.com/google/go-github/v25/github"
1010
"github.com/hashicorp/terraform/helper/schema"
1111
)
1212

@@ -51,12 +51,12 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
5151
client := meta.(*Organization).client
5252
ctx := context.Background()
5353

54-
team, err := getGithubTeamBySlug(client, meta.(*Organization).name, slug)
54+
team, err := getGithubTeamBySlug(ctx, client, meta.(*Organization).name, slug)
5555
if err != nil {
5656
return err
5757
}
5858

59-
member, _, err := client.Organizations.ListTeamMembers(ctx, team.GetID(), nil)
59+
member, _, err := client.Teams.ListTeamMembers(ctx, team.GetID(), nil)
6060
if err != nil {
6161
return err
6262
}
@@ -76,10 +76,10 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
7676
return nil
7777
}
7878

79-
func getGithubTeamBySlug(client *github.Client, org string, slug string) (team *github.Team, err error) {
79+
func getGithubTeamBySlug(ctx context.Context, client *github.Client, org string, slug string) (team *github.Team, err error) {
8080
opt := &github.ListOptions{PerPage: 10}
8181
for {
82-
teams, resp, err := client.Organizations.ListTeams(context.TODO(), org, opt)
82+
teams, resp, err := client.Teams.ListTeams(ctx, org, opt)
8383
if err != nil {
8484
return team, err
8585
}

github/provider.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,27 @@ func Provider() terraform.ResourceProvider {
3939
"github_branch_protection": resourceGithubBranchProtection(),
4040
"github_issue_label": resourceGithubIssueLabel(),
4141
"github_membership": resourceGithubMembership(),
42+
"github_organization_block": resourceOrganizationBlock(),
4243
"github_organization_project": resourceGithubOrganizationProject(),
4344
"github_organization_webhook": resourceGithubOrganizationWebhook(),
4445
"github_project_column": resourceGithubProjectColumn(),
45-
"github_repository": resourceGithubRepository(),
4646
"github_repository_collaborator": resourceGithubRepositoryCollaborator(),
4747
"github_repository_deploy_key": resourceGithubRepositoryDeployKey(),
4848
"github_repository_project": resourceGithubRepositoryProject(),
4949
"github_repository_webhook": resourceGithubRepositoryWebhook(),
50-
"github_team": resourceGithubTeam(),
50+
"github_repository": resourceGithubRepository(),
5151
"github_team_membership": resourceGithubTeamMembership(),
5252
"github_team_repository": resourceGithubTeamRepository(),
53+
"github_team": resourceGithubTeam(),
5354
"github_user_gpg_key": resourceGithubUserGpgKey(),
5455
"github_user_invitation_accepter": resourceGithubUserInvitationAccepter(),
5556
"github_user_ssh_key": resourceGithubUserSshKey(),
5657
},
5758

5859
DataSourcesMap: map[string]*schema.Resource{
5960
"github_ip_ranges": dataSourceGithubIpRanges(),
60-
"github_repository": dataSourceGithubRepository(),
6161
"github_repositories": dataSourceGithubRepositories(),
62+
"github_repository": dataSourceGithubRepository(),
6263
"github_team": dataSourceGithubTeam(),
6364
"github_user": dataSourceGithubUser(),
6465
},

github/resource_github_branch_protection.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"log"
88
"net/http"
99

10-
"github.com/google/go-github/github"
10+
"github.com/google/go-github/v25/github"
1111
"github.com/hashicorp/terraform/helper/schema"
12+
"github.com/hashicorp/terraform/helper/validation"
1213
)
1314

1415
func resourceGithubBranchProtection() *schema.Resource {
@@ -96,6 +97,12 @@ func resourceGithubBranchProtection() *schema.Resource {
9697
Type: schema.TypeBool,
9798
Optional: true,
9899
},
100+
"required_approving_review_count": {
101+
Type: schema.TypeInt,
102+
Optional: true,
103+
Default: 1,
104+
ValidateFunc: validation.IntBetween(1, 6),
105+
},
99106
},
100107
},
101108
},
@@ -338,10 +345,11 @@ func flattenAndSetRequiredPullRequestReviews(d *schema.ResourceData, protection
338345

339346
return d.Set("required_pull_request_reviews", []interface{}{
340347
map[string]interface{}{
341-
"dismiss_stale_reviews": rprr.DismissStaleReviews,
342-
"dismissal_users": schema.NewSet(schema.HashString, users),
343-
"dismissal_teams": schema.NewSet(schema.HashString, teams),
344-
"require_code_owner_reviews": rprr.RequireCodeOwnerReviews,
348+
"dismiss_stale_reviews": rprr.DismissStaleReviews,
349+
"dismissal_users": schema.NewSet(schema.HashString, users),
350+
"dismissal_teams": schema.NewSet(schema.HashString, teams),
351+
"require_code_owner_reviews": rprr.RequireCodeOwnerReviews,
352+
"required_approving_review_count": rprr.RequiredApprovingReviewCount,
345353
},
346354
})
347355
}
@@ -427,6 +435,7 @@ func expandRequiredPullRequestReviews(d *schema.ResourceData) (*github.PullReque
427435
rprr.DismissalRestrictionsRequest = drr
428436
rprr.DismissStaleReviews = m["dismiss_stale_reviews"].(bool)
429437
rprr.RequireCodeOwnerReviews = m["require_code_owner_reviews"].(bool)
438+
rprr.RequiredApprovingReviewCount = m["required_approving_review_count"].(int)
430439
}
431440

432441
return rprr, nil

github/resource_github_branch_protection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sort"
77
"testing"
88

9-
"github.com/google/go-github/github"
9+
"github.com/google/go-github/v25/github"
1010
"github.com/hashicorp/terraform/helper/acctest"
1111
"github.com/hashicorp/terraform/helper/resource"
1212
"github.com/hashicorp/terraform/terraform"

github/resource_github_issue_label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66
"net/http"
77

8-
"github.com/google/go-github/github"
8+
"github.com/google/go-github/v25/github"
99
"github.com/hashicorp/terraform/helper/schema"
1010
)
1111

github/resource_github_issue_label_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"testing"
77

8-
"github.com/google/go-github/github"
8+
"github.com/google/go-github/v25/github"
99
"github.com/hashicorp/terraform/helper/acctest"
1010
"github.com/hashicorp/terraform/helper/resource"
1111
"github.com/hashicorp/terraform/terraform"

github/resource_github_membership.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66
"net/http"
77

8-
"github.com/google/go-github/github"
8+
"github.com/google/go-github/v25/github"
99
"github.com/hashicorp/terraform/helper/schema"
1010
)
1111

github/resource_github_membership_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"testing"
77

8-
"github.com/google/go-github/github"
8+
"github.com/google/go-github/v25/github"
99
"github.com/hashicorp/terraform/helper/resource"
1010
"github.com/hashicorp/terraform/terraform"
1111
)

github/resource_github_organization_project.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"net/http"
88
"strconv"
99

10-
"github.com/google/go-github/github"
10+
"github.com/google/go-github/v25/github"
1111
"github.com/hashicorp/terraform/helper/schema"
1212
)
1313

@@ -46,14 +46,15 @@ func resourceGithubOrganizationProjectCreate(d *schema.ResourceData, meta interf
4646
client := meta.(*Organization).client
4747
orgName := meta.(*Organization).name
4848
name := d.Get("name").(string)
49+
body := d.Get("body").(string)
4950
ctx := context.Background()
5051

5152
log.Printf("[DEBUG] Creating organization project: %s (%s)", name, orgName)
5253
project, _, err := client.Organizations.CreateProject(ctx,
5354
orgName,
5455
&github.ProjectOptions{
55-
Name: name,
56-
Body: d.Get("body").(string),
56+
Name: &name,
57+
Body: &body,
5758
},
5859
)
5960
if err != nil {
@@ -105,12 +106,14 @@ func resourceGithubOrganizationProjectRead(d *schema.ResourceData, meta interfac
105106

106107
func resourceGithubOrganizationProjectUpdate(d *schema.ResourceData, meta interface{}) error {
107108
client := meta.(*Organization).client
108-
109109
orgName := meta.(*Organization).name
110+
110111
name := d.Get("name").(string)
112+
body := d.Get("body").(string)
113+
111114
options := github.ProjectOptions{
112-
Name: name,
113-
Body: d.Get("body").(string),
115+
Name: &name,
116+
Body: &body,
114117
}
115118

116119
projectID, err := strconv.ParseInt(d.Id(), 10, 64)

github/resource_github_organization_project_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
"testing"
99

10-
"github.com/google/go-github/github"
10+
"github.com/google/go-github/v25/github"
1111
"github.com/hashicorp/terraform/helper/resource"
1212
"github.com/hashicorp/terraform/terraform"
1313
)

github/resource_github_organization_webhook.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package github
22

33
import (
44
"context"
5-
"fmt"
65
"log"
76
"net/http"
87
"strconv"
98

10-
"github.com/google/go-github/github"
9+
"github.com/google/go-github/v25/github"
1110
"github.com/hashicorp/terraform/helper/schema"
1211
)
1312

@@ -23,12 +22,6 @@ func resourceGithubOrganizationWebhook() *schema.Resource {
2322
MigrateState: resourceGithubWebhookMigrateState,
2423

2524
Schema: map[string]*schema.Schema{
26-
"name": {
27-
Type: schema.TypeString,
28-
Required: true,
29-
ForceNew: true,
30-
ValidateFunc: validateGithubOrganizationWebhookName,
31-
},
3225
"events": {
3326
Type: schema.TypeSet,
3427
Required: true,
@@ -53,13 +46,6 @@ func resourceGithubOrganizationWebhook() *schema.Resource {
5346
}
5447
}
5548

56-
func validateGithubOrganizationWebhookName(v interface{}, k string) (ws []string, errors []error) {
57-
if v.(string) != "web" {
58-
errors = append(errors, fmt.Errorf("Github: name can only be web"))
59-
}
60-
return
61-
}
62-
6349
func resourceGithubOrganizationWebhookObject(d *schema.ResourceData) *github.Hook {
6450
events := []string{}
6551
eventSet := d.Get("events").(*schema.Set)
@@ -68,7 +54,6 @@ func resourceGithubOrganizationWebhookObject(d *schema.ResourceData) *github.Hoo
6854
}
6955

7056
hook := &github.Hook{
71-
Name: github.String(d.Get("name").(string)),
7257
URL: github.String(d.Get("url").(string)),
7358
Events: events,
7459
Active: github.Bool(d.Get("active").(bool)),
@@ -89,8 +74,7 @@ func resourceGithubOrganizationWebhookCreate(d *schema.ResourceData, meta interf
8974
webhookObj := resourceGithubOrganizationWebhookObject(d)
9075
ctx := context.Background()
9176

92-
log.Printf("[DEBUG] Creating organization webhook: %s (%s)",
93-
webhookObj.GetName(), orgName)
77+
log.Printf("[DEBUG] Creating organization webhook: %d (%s)", webhookObj.GetID(), orgName)
9478
hook, _, err := client.Organizations.CreateHook(ctx, orgName, webhookObj)
9579

9680
if err != nil {
@@ -132,7 +116,6 @@ func resourceGithubOrganizationWebhookRead(d *schema.ResourceData, meta interfac
132116
}
133117

134118
d.Set("etag", resp.Header.Get("ETag"))
135-
d.Set("name", hook.Name)
136119
d.Set("url", hook.URL)
137120
d.Set("active", hook.Active)
138121
d.Set("events", hook.Events)

github/resource_github_organization_webhook_test.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"testing"
1010

11-
"github.com/google/go-github/github"
11+
"github.com/google/go-github/v25/github"
1212
"github.com/hashicorp/terraform/helper/resource"
1313
"github.com/hashicorp/terraform/terraform"
1414
)
@@ -26,12 +26,11 @@ func TestAccGithubOrganizationWebhook_basic(t *testing.T) {
2626
Check: resource.ComposeTestCheckFunc(
2727
testAccCheckGithubOrganizationWebhookExists("github_organization_webhook.foo", &hook),
2828
testAccCheckGithubOrganizationWebhookAttributes(&hook, &testAccGithubOrganizationWebhookExpectedAttributes{
29-
Name: "web",
3029
Events: []string{"pull_request"},
3130
Configuration: map[string]interface{}{
3231
"url": "https://google.de/webhook",
3332
"content_type": "json",
34-
"insecure_ssl": "1",
33+
"insecure_ssl": "true",
3534
},
3635
Active: true,
3736
}),
@@ -42,12 +41,11 @@ func TestAccGithubOrganizationWebhook_basic(t *testing.T) {
4241
Check: resource.ComposeTestCheckFunc(
4342
testAccCheckGithubOrganizationWebhookExists("github_organization_webhook.foo", &hook),
4443
testAccCheckGithubOrganizationWebhookAttributes(&hook, &testAccGithubOrganizationWebhookExpectedAttributes{
45-
Name: "web",
4644
Events: []string{"issues"},
4745
Configuration: map[string]interface{}{
4846
"url": "https://google.de/webhooks",
4947
"content_type": "form",
50-
"insecure_ssl": "0",
48+
"insecure_ssl": "false",
5149
},
5250
Active: false,
5351
}),
@@ -70,13 +68,12 @@ func TestAccGithubOrganizationWebhook_secret(t *testing.T) {
7068
Check: resource.ComposeTestCheckFunc(
7169
testAccCheckGithubOrganizationWebhookExists("github_organization_webhook.foo", &hook),
7270
testAccCheckGithubOrganizationWebhookAttributes(&hook, &testAccGithubOrganizationWebhookExpectedAttributes{
73-
Name: "web",
7471
Events: []string{"pull_request"},
7572
Configuration: map[string]interface{}{
7673
"url": "https://www.terraform.io/webhook",
7774
"content_type": "json",
7875
"secret": "********",
79-
"insecure_ssl": "0",
76+
"insecure_ssl": "false",
8077
},
8178
Active: true,
8279
}),
@@ -113,7 +110,6 @@ func testAccCheckGithubOrganizationWebhookExists(n string, hook *github.Hook) re
113110
}
114111

115112
type testAccGithubOrganizationWebhookExpectedAttributes struct {
116-
Name string
117113
Events []string
118114
Configuration map[string]interface{}
119115
Active bool
@@ -122,9 +118,6 @@ type testAccGithubOrganizationWebhookExpectedAttributes struct {
122118
func testAccCheckGithubOrganizationWebhookAttributes(hook *github.Hook, want *testAccGithubOrganizationWebhookExpectedAttributes) resource.TestCheckFunc {
123119
return func(s *terraform.State) error {
124120

125-
if *hook.Name != want.Name {
126-
return fmt.Errorf("got hook %q; want %q", *hook.Name, want.Name)
127-
}
128121
if *hook.Active != want.Active {
129122
return fmt.Errorf("got hook %t; want %t", *hook.Active, want.Active)
130123
}
@@ -172,7 +165,6 @@ func testAccCheckGithubOrganizationWebhookDestroy(s *terraform.State) error {
172165

173166
const testAccGithubOrganizationWebhookConfig = `
174167
resource "github_organization_webhook" "foo" {
175-
name = "web"
176168
configuration {
177169
url = "https://google.de/webhook"
178170
content_type = "json"
@@ -185,7 +177,6 @@ resource "github_organization_webhook" "foo" {
185177

186178
const testAccGithubOrganizationWebhookUpdateConfig = `
187179
resource "github_organization_webhook" "foo" {
188-
name = "web"
189180
configuration {
190181
url = "https://google.de/webhooks"
191182
content_type = "form"
@@ -199,7 +190,6 @@ resource "github_organization_webhook" "foo" {
199190

200191
const testAccGithubOrganizationWebhookConfig_secret = `
201192
resource "github_organization_webhook" "foo" {
202-
name = "web"
203193
configuration {
204194
url = "https://www.terraform.io/webhook"
205195
content_type = "json"

0 commit comments

Comments
 (0)