Skip to content

Commit

Permalink
feat(github_ip_ranges): support for Web and API IP Ranges (#1220)
Browse files Browse the repository at this point in the history
* feat(github_ip_ranges): support for web and api CIDR blocks from meta API.

* fix: Api --> API as per sdk changes. Re-adding accidentally removed Pages.

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
Jamian and kfcampbell authored Aug 30, 2022
1 parent b60a8af commit c753688
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
50 changes: 50 additions & 0 deletions github/data_source_github_ip_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ func dataSourceGithubIpRanges() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"web": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"api": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"pages": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -52,6 +62,16 @@ func dataSourceGithubIpRanges() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"web_ipv4": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"api_ipv4": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"pages_ipv4": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -82,6 +102,16 @@ func dataSourceGithubIpRanges() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"web_ipv6": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"api_ipv6": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"pages_ipv6": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -144,6 +174,16 @@ func dataSourceGithubIpRangesRead(d *schema.ResourceData, meta interface{}) erro
return err
}

cidrWebIpv4, cidrWebIpv6, err := splitIpv4Ipv6Cidrs(&api.Web)
if err != nil {
return err
}

cidrApiIpv4, cidrApiIpv6, err := splitIpv4Ipv6Cidrs(&api.API)
if err != nil {
return err
}

if len(api.Hooks)+len(api.Git)+len(api.Pages)+len(api.Importer)+len(api.Actions)+len(api.Dependabot) > 0 {
d.SetId("github-ip-ranges")
}
Expand Down Expand Up @@ -177,6 +217,16 @@ func dataSourceGithubIpRangesRead(d *schema.ResourceData, meta interface{}) erro
d.Set("dependabot_ipv4", cidrDependabotIpv4)
d.Set("dependabot_ipv6", cidrDependabotIpv6)
}
if len(api.Web) > 0 {
d.Set("web", api.Web)
d.Set("web_ipv4", cidrWebIpv4)
d.Set("web_ipv6", cidrWebIpv6)
}
if len(api.API) > 0 {
d.Set("api", api.API)
d.Set("api_ipv4", cidrApiIpv4)
d.Set("api_ipv6", cidrApiIpv6)
}

return nil
}
Expand Down
6 changes: 6 additions & 0 deletions github/data_source_github_ip_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@ func TestAccGithubIpRangesDataSource(t *testing.T) {
check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "hooks.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "git.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "api.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "web.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "pages.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "importer.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "actions.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "dependabot.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "hooks_ipv4.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "git_ipv4.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "api_ipv4.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "web_ipv4.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "pages_ipv4.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "importer_ipv4.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "actions_ipv4.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "dependabot_ipv4.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "hooks_ipv6.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "git_ipv6.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "api_ipv6.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "web_ipv6.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "pages_ipv6.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "importer_ipv6.#"),
resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "actions_ipv6.#"),
Expand Down
6 changes: 6 additions & 0 deletions website/docs/d/ip_ranges.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ data "github_ip_ranges" "test" {}
* `git` - An Array of IP addresses in CIDR format specifying the Git servers.
* `git_ipv4` - A subset of the `git` array that contains IP addresses in IPv4 CIDR format.
* `git_ipv6` - A subset of the `git` array that contains IP addresses in IPv6 CIDR format.
* `web` - An Array of IP addresses in CIDR format for GitHub Web.
* `web_ipv4` - A subset of the `web` array that contains IP addresses in IPv4 CIDR format.
* `web_ipv6` - A subset of the `web` array that contains IP addresses in IPv6 CIDR format.
* `api` - An Array of IP addresses in CIDR format for the GitHub API.
* `api_ipv4` - A subset of the `api` array that contains IP addresses in IPv4 CIDR format.
* `api_ipv6` - A subset of the `api` array that contains IP addresses in IPv6 CIDR format.
* `pages` - An Array of IP addresses in CIDR format specifying the A records for GitHub Pages.
* `pages_ipv4` - A subset of the `pages` array that contains IP addresses in IPv4 CIDR format.
* `pages_ipv6` - A subset of the `pages` array that contains IP addresses in IPv6 CIDR format.
Expand Down

0 comments on commit c753688

Please sign in to comment.