Skip to content

Commit 16872b7

Browse files
kfcampbelldcfrancanickfloydfelixlutgeorgekaz
authored
v6 (#2091)
* Add retryable transport for errors (#1704) * Add retryable transport for errors In order to address the issue #210 I have added 3 new parameters to the provider - retry_delay_ms - max_retries - retryable_errors In case max_retries is > 0 (defaults to zero) it will retry the request in case it is an error the retryable_errors defaults to [500, 502, 503, 504] It retries after the ms specified in retry_delay_ms (defaults to 1000) * Update documentation with new parameters for retry * Change default of max_retries to 3 * Fix typo in naming * Update github/transport_test.go * Add error check for data seek * Consolidate the default retriable errors on a function * Fix typo on the comments Co-authored-by: Keegan Campbell <[email protected]> * Update vendor * Fix merging conflicts * Update documentation with new parameters for retry * Change default of max_retries to 3 * Fix typo in naming * Add error check for data seek * Update github/transport_test.go * Consolidate the default retriable errors on a function * Fix typo on the comments Co-authored-by: Keegan Campbell <[email protected]> * Don't run go mod tidy on release (#1788) * Don't run go mod tidy on release * Be more specific about releases * Fix lint with APIMeta deprecation --------- Co-authored-by: Keegan Campbell <[email protected]> Co-authored-by: Nick Floyd <[email protected]> * fix: remove repository topic from state if it doesnt exist in GitHub anymore (#1918) * remove repository topic if they cannot be found in GitHub anymore * Fix build error by bumping package version in offending file --------- Co-authored-by: Keegan Campbell <[email protected]> * Bump version to v6 (#2106) * Upgrade to Terraform Plugin SDK v2 (#1780) * go mod tidy -go=1.16 && go mod tidy -go=1.17 * Run go mod vendor * Attempt v2 upgrade * Plugin compiling * Fix some provider test errors * Fix test compilation error * ValidateFunc --> ValidateDiagFunc * Fix casing * Sprinkle toDiagFunc everywhere * More fixes for validation functions * State --> StateContext * %s --> %v when printing diags * ConfigureFunc --> ConfigureContextFunc * Checking results of d.Set, round one * Continue checking d.Set results * Check results of d.Set, round three * Checking d.Set results, round four * d.Set round five * In tests, export GITHUB_TEST_ORGANIZATION * Remove unnecessary MaxItems on computed value * Go build now works * Resolve linting errors * Apply diag.FromErr twice more * Pass key names into toDiagFunc helper * Construct cty.Path from strings * Tests now working * Update terraform-plugin-sdk version * Remove commented attribute setting in resource_github_team.go * Fix restrict pushes on github_branch_protection. Fix branch protection tests (#2045) * Update restrict pushes. Fix branch protection tests Change blocks_creations default to true. Fix broken build. * add state migration * rename push_restrictions to push_allowances * correct state migration issue * add docs clarification * update migration func args * fix test args * cleanup tests * Pass context.Background() in test * fix timestamp fields --------- Co-authored-by: Keegan Campbell <[email protected]> * Set group_id correctly (#2133) * Run go get -u github.com/golangci/golangci-lint * Separate github_team_members import from github_team as create_default_maintainers is not defined for members resource (#2126) Co-authored-by: Keegan Campbell <[email protected]> * Add missing variable definition for test case --------- Co-authored-by: Daniel França <[email protected]> Co-authored-by: Nick Floyd <[email protected]> Co-authored-by: Felix Luthman <[email protected]> Co-authored-by: georgekaz <[email protected]> Co-authored-by: Rich Young <[email protected]>
1 parent 2d31318 commit 16872b7

File tree

4,216 files changed

+232773
-467694
lines changed

Some content is hidden

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

4,216 files changed

+232773
-467694
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
jobs:
99
ci:
1010
runs-on: ubuntu-latest
11+
env:
12+
GITHUB_TEST_ORGANIZATION: 'kfcampbell-terraform-provider'
1113
steps:
1214
- uses: actions/checkout@v4
1315
- uses: actions/setup-go@v5

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ linters:
2121

2222
linters-settings:
2323
errcheck:
24-
ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close
24+
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close
2525

github/config.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/google/go-github/v57/github"
12-
"github.com/hashicorp/terraform-plugin-sdk/helper/logging"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
1313
"github.com/shurcooL/githubv4"
1414
"golang.org/x/oauth2"
1515
)
@@ -21,6 +21,9 @@ type Config struct {
2121
Insecure bool
2222
WriteDelay time.Duration
2323
ReadDelay time.Duration
24+
RetryDelay time.Duration
25+
RetryableErrors map[int]bool
26+
MaxRetries int
2427
ParallelRequests bool
2528
}
2629

@@ -33,16 +36,20 @@ type Owner struct {
3336
IsOrganization bool
3437
}
3538

36-
func RateLimitedHTTPClient(client *http.Client, writeDelay time.Duration, readDelay time.Duration, parallelRequests bool) *http.Client {
39+
func RateLimitedHTTPClient(client *http.Client, writeDelay time.Duration, readDelay time.Duration, retryDelay time.Duration, parallelRequests bool, retryableErrors map[int]bool, maxRetries int) *http.Client {
3740

3841
client.Transport = NewEtagTransport(client.Transport)
3942
client.Transport = NewRateLimitTransport(client.Transport, WithWriteDelay(writeDelay), WithReadDelay(readDelay), WithParallelRequests(parallelRequests))
40-
client.Transport = logging.NewTransport("GitHub", client.Transport)
43+
client.Transport = logging.NewSubsystemLoggingHTTPTransport("GitHub", client.Transport)
4144
client.Transport = newPreviewHeaderInjectorTransport(map[string]string{
4245
// TODO: remove when Stone Crop preview is moved to general availability in the GraphQL API
4346
"Accept": "application/vnd.github.stone-crop-preview+json",
4447
}, client.Transport)
4548

49+
if maxRetries > 0 {
50+
client.Transport = NewRetryTransport(client.Transport, WithRetryDelay(retryDelay), WithRetryableErrors(retryableErrors), WithMaxRetries(maxRetries))
51+
}
52+
4653
return client
4754
}
4855

@@ -54,7 +61,7 @@ func (c *Config) AuthenticatedHTTPClient() *http.Client {
5461
)
5562
client := oauth2.NewClient(ctx, ts)
5663

57-
return RateLimitedHTTPClient(client, c.WriteDelay, c.ReadDelay, c.ParallelRequests)
64+
return RateLimitedHTTPClient(client, c.WriteDelay, c.ReadDelay, c.RetryDelay, c.ParallelRequests, c.RetryableErrors, c.MaxRetries)
5865
}
5966

6067
func (c *Config) Anonymous() bool {
@@ -63,7 +70,7 @@ func (c *Config) Anonymous() bool {
6370

6471
func (c *Config) AnonymousHTTPClient() *http.Client {
6572
client := &http.Client{Transport: &http.Transport{}}
66-
return RateLimitedHTTPClient(client, c.WriteDelay, c.ReadDelay, c.ParallelRequests)
73+
return RateLimitedHTTPClient(client, c.WriteDelay, c.ReadDelay, c.RetryDelay, c.ParallelRequests, c.RetryableErrors, c.MaxRetries)
6774
}
6875

6976
func (c *Config) NewGraphQLClient(client *http.Client) (*githubv4.Client, error) {
@@ -130,7 +137,7 @@ func (c *Config) ConfigureOwner(owner *Owner) (*Owner, error) {
130137
}
131138

132139
// Meta returns the meta parameter that is passed into subsequent resources
133-
// https://godoc.org/github.com/hashicorp/terraform-plugin-sdk/helper/schema#ConfigureFunc
140+
// https://godoc.org/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#ConfigureFunc
134141
func (c *Config) Meta() (interface{}, error) {
135142

136143
var client *http.Client
@@ -153,6 +160,7 @@ func (c *Config) Meta() (interface{}, error) {
153160
var owner Owner
154161
owner.v4client = v4client
155162
owner.v3client = v3client
163+
owner.StopContext = context.Background()
156164

157165
_, err = c.ConfigureOwner(&owner)
158166
if err != nil {

github/config_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ func TestAccConfigMeta(t *testing.T) {
5858

5959
})
6060

61+
t.Run("returns a v3 REST API client with max retries", func(t *testing.T) {
62+
63+
config := Config{
64+
Token: testToken,
65+
BaseURL: "https://api.github.com/",
66+
RetryableErrors: map[int]bool{
67+
500: true,
68+
502: true,
69+
},
70+
MaxRetries: 3,
71+
}
72+
meta, err := config.Meta()
73+
if err != nil {
74+
t.Fatalf("failed to return meta without error: %s", err.Error())
75+
}
76+
77+
ctx := context.Background()
78+
client := meta.(*Owner).v3client
79+
_, _, err = client.Meta.Get(ctx)
80+
if err != nil {
81+
t.Fatalf("failed to validate returned client without error: %s", err.Error())
82+
}
83+
84+
})
85+
6186
t.Run("returns a v4 GraphQL API client to manage individual resources", func(t *testing.T) {
6287

6388
config := Config{

github/data_source_github_actions_environment_secrets.go

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

88
"github.com/google/go-github/v57/github"
99

10-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
)
1212

1313
func dataSourceGithubActionsEnvironmentSecrets() *schema.Resource {

github/data_source_github_actions_environment_secrets_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
8-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
99
)
1010

1111
func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) {

github/data_source_github_actions_environment_variables.go

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

88
"github.com/google/go-github/v57/github"
99

10-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
)
1212

1313
func dataSourceGithubActionsEnvironmentVariables() *schema.Resource {

github/data_source_github_actions_environment_variables_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
9-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1010
)
1111

1212
func TestAccGithubActionsEnvironmentVariablesDataSource(t *testing.T) {

github/data_source_github_actions_organization_oidc_subject_claim_customization_template.go

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

33
import (
4-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
55
)
66

77
func dataSourceGithubActionsOrganizationOIDCSubjectClaimCustomizationTemplate() *schema.Resource {
@@ -38,7 +38,10 @@ func dataSourceGithubActionsOrganizationOIDCSubjectClaimCustomizationTemplateRea
3838
}
3939

4040
d.SetId(orgName)
41-
d.Set("include_claim_keys", template.IncludeClaimKeys)
41+
err = d.Set("include_claim_keys", template.IncludeClaimKeys)
42+
if err != nil {
43+
return err
44+
}
4245

4346
return nil
4447
}

github/data_source_github_actions_organization_oidc_subject_claim_customization_template_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package github
33
import (
44
"testing"
55

6-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
77
)
88

99
func TestAccGithubActionsOrganizationOIDCSubjectClaimCustomizationTemplateDataSource(t *testing.T) {

github/data_source_github_actions_organization_public_key.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package github
33
import (
44
"context"
55

6-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
77
)
88

99
func dataSourceGithubActionsOrganizationPublicKey() *schema.Resource {
@@ -40,8 +40,14 @@ func dataSourceGithubActionsOrganizationPublicKeyRead(d *schema.ResourceData, me
4040
}
4141

4242
d.SetId(publicKey.GetKeyID())
43-
d.Set("key_id", publicKey.GetKeyID())
44-
d.Set("key", publicKey.GetKey())
43+
err = d.Set("key_id", publicKey.GetKeyID())
44+
if err != nil {
45+
return err
46+
}
47+
err = d.Set("key", publicKey.GetKey())
48+
if err != nil {
49+
return err
50+
}
4551

4652
return nil
4753
}

github/data_source_github_actions_organization_public_key_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package github
33
import (
44
"testing"
55

6-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
77
)
88

99
func TestAccGithubActionsOrganizationPublicKeyDataSource(t *testing.T) {

github/data_source_github_actions_organization_registration_token.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"log"
77

8-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
)
1010

1111
func dataSourceGithubActionsOrganizationRegistrationToken() *schema.Resource {
@@ -36,8 +36,14 @@ func dataSourceGithubActionsOrganizationRegistrationTokenRead(d *schema.Resource
3636
}
3737

3838
d.SetId(owner)
39-
d.Set("token", token.Token)
40-
d.Set("expires_at", token.ExpiresAt.Unix())
39+
err = d.Set("token", token.Token)
40+
if err != nil {
41+
return err
42+
}
43+
err = d.Set("expires_at", token.ExpiresAt.Unix())
44+
if err != nil {
45+
return err
46+
}
4147

4248
return nil
4349
}

github/data_source_github_actions_organization_registration_token_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package github
33
import (
44
"testing"
55

6-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
77
)
88

99
func TestAccGithubActionsOrganizationRegistrationTokenDataSource(t *testing.T) {

github/data_source_github_actions_organization_secrets.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/google/go-github/v57/github"
77

8-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
)
1010

1111
func dataSourceGithubActionsOrganizationSecrets() *schema.Resource {
@@ -72,7 +72,10 @@ func dataSourceGithubActionsOrganizationSecretsRead(d *schema.ResourceData, meta
7272
}
7373

7474
d.SetId(owner)
75-
d.Set("secrets", all_secrets)
75+
err := d.Set("secrets", all_secrets)
76+
if err != nil {
77+
return err
78+
}
7679

7780
return nil
7881
}

github/data_source_github_actions_organization_secrets_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
9-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1010
)
1111

1212
func TestAccGithubActionsOrganizationSecretsDataSource(t *testing.T) {

github/data_source_github_actions_organization_variables.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/google/go-github/v57/github"
77

8-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
)
1010

1111
func dataSourceGithubActionsOrganizationVariables() *schema.Resource {
@@ -76,7 +76,10 @@ func dataSourceGithubActionsOrganizationVariablesRead(d *schema.ResourceData, me
7676
}
7777

7878
d.SetId(owner)
79-
d.Set("variables", all_variables)
79+
err := d.Set("variables", all_variables)
80+
if err != nil {
81+
return err
82+
}
8083

8184
return nil
8285
}

github/data_source_github_actions_organization_variables_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
9-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1010
)
1111

1212
func TestAccGithubActionsOrganizationVariablesDataSource(t *testing.T) {

github/data_source_github_actions_public_key.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package github
33
import (
44
"context"
55

6-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
77
)
88

99
func dataSourceGithubActionsPublicKey() *schema.Resource {
@@ -40,8 +40,14 @@ func dataSourceGithubActionsPublicKeyRead(d *schema.ResourceData, meta interface
4040
}
4141

4242
d.SetId(publicKey.GetKeyID())
43-
d.Set("key_id", publicKey.GetKeyID())
44-
d.Set("key", publicKey.GetKey())
43+
err = d.Set("key_id", publicKey.GetKeyID())
44+
if err != nil {
45+
return err
46+
}
47+
err = d.Set("key", publicKey.GetKey())
48+
if err != nil {
49+
return err
50+
}
4551

4652
return nil
4753
}

github/data_source_github_actions_public_key_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
8-
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
99
)
1010

1111
func TestAccGithubActionsPublicKeyDataSource(t *testing.T) {

github/data_source_github_actions_registration_token.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"log"
77

8-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
)
1010

1111
func dataSourceGithubActionsRegistrationToken() *schema.Resource {
@@ -42,8 +42,14 @@ func dataSourceGithubActionsRegistrationTokenRead(d *schema.ResourceData, meta i
4242
}
4343

4444
d.SetId(fmt.Sprintf("%s/%s", owner, repoName))
45-
d.Set("token", token.Token)
46-
d.Set("expires_at", token.ExpiresAt.Unix())
45+
err = d.Set("token", token.Token)
46+
if err != nil {
47+
return err
48+
}
49+
err = d.Set("expires_at", token.ExpiresAt.Unix())
50+
if err != nil {
51+
return err
52+
}
4753

4854
return nil
4955
}

0 commit comments

Comments
 (0)