Skip to content
Open
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
6 changes: 6 additions & 0 deletions docs/data-sources/ip_ranges.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion github/data_source_github_ip_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions github/data_source_github_ip_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ package github

import (
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"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" {}`
Expand Down
6 changes: 6 additions & 0 deletions templates/data-sources/ip_ranges.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down