diff --git a/docs/data-sources/ip_ranges.md b/docs/data-sources/ip_ranges.md index caeb7a51b2..2a43b03998 100644 --- a/docs/data-sources/ip_ranges.md +++ b/docs/data-sources/ip_ranges.md @@ -14,6 +14,12 @@ Use this data source to retrieve information about GitHub's IP addresses. data "github_ip_ranges" "test" {} ``` +## Timeouts + +The `timeouts` block allows you to configure [timeouts](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts) for certain actions: + +* `read` - (Defaults to 5 minutes) Used when reading the GitHub IP ranges from the metadata API. + ## Attributes Reference - `actions` - An array of IP addresses in CIDR format specifying the addresses that incoming requests from GitHub Actions will originate from. diff --git a/github/data_source_github_ip_ranges.go b/github/data_source_github_ip_ranges.go index f92e687542..87b2ef977d 100644 --- a/github/data_source_github_ip_ranges.go +++ b/github/data_source_github_ip_ranges.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net" + "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -13,6 +14,9 @@ func dataSourceGithubIpRanges() *schema.Resource { return &schema.Resource{ Description: "Get the GitHub IP ranges used by various GitHub services.", ReadContext: dataSourceGithubIpRangesRead, + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, Schema: map[string]*schema.Schema{ "hooks": { Type: schema.TypeList, @@ -198,7 +202,7 @@ func dataSourceGithubIpRanges() *schema.Resource { func dataSourceGithubIpRangesRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { owner := meta.(*Owner) - api, _, err := owner.v3client.Meta.Get(owner.StopContext) + api, _, err := owner.v3client.Meta.Get(ctx) if err != nil { return diag.FromErr(err) } diff --git a/github/data_source_github_ip_ranges_test.go b/github/data_source_github_ip_ranges_test.go index 74eaf62d2f..713ce1b9fb 100644 --- a/github/data_source_github_ip_ranges_test.go +++ b/github/data_source_github_ip_ranges_test.go @@ -2,6 +2,7 @@ package github import ( "testing" + "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" @@ -9,6 +10,21 @@ import ( "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" ) +func TestUnitGithubIpRangesDataSource_schemaTimeouts(t *testing.T) { + t.Parallel() + + r := dataSourceGithubIpRanges() + if r.Timeouts == nil { + t.Fatal("expected Timeouts to be configured on github_ip_ranges data source") + } + if r.Timeouts.Read == nil { + t.Fatal("expected default read timeout to be configured") + } + if got := *r.Timeouts.Read; got != 5*time.Minute { + t.Fatalf("expected default read timeout 5m, got %v", got) + } +} + func TestAccGithubIpRangesDataSource(t *testing.T) { t.Run("reads IP ranges without error", func(t *testing.T) { config := `data "github_ip_ranges" "test" {}` diff --git a/templates/data-sources/ip_ranges.md.tmpl b/templates/data-sources/ip_ranges.md.tmpl index 9d19c4dcb3..69769ad06c 100644 --- a/templates/data-sources/ip_ranges.md.tmpl +++ b/templates/data-sources/ip_ranges.md.tmpl @@ -12,6 +12,12 @@ Use this data source to retrieve information about GitHub's IP addresses. {{ tffile "examples/data-sources/ip_ranges/example_1.tf" }} +## Timeouts + +The `timeouts` block allows you to configure [timeouts](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts) for certain actions: + +* `read` - (Defaults to 5 minutes) Used when reading the GitHub IP ranges from the metadata API. + ## Attributes Reference - `actions` - An array of IP addresses in CIDR format specifying the addresses that incoming requests from GitHub Actions will originate from.