From c753688130cbc907fa42e4e96624dae4eeca7864 Mon Sep 17 00:00:00 2001 From: Jamie West Date: Tue, 30 Aug 2022 18:39:45 +0100 Subject: [PATCH] feat(github_ip_ranges): support for Web and API IP Ranges (#1220) * 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 --- github/data_source_github_ip_ranges.go | 50 +++++++++++++++++++++ github/data_source_github_ip_ranges_test.go | 6 +++ website/docs/d/ip_ranges.html.markdown | 6 +++ 3 files changed, 62 insertions(+) diff --git a/github/data_source_github_ip_ranges.go b/github/data_source_github_ip_ranges.go index 8cb061ec93..a3e580c8e7 100644 --- a/github/data_source_github_ip_ranges.go +++ b/github/data_source_github_ip_ranges.go @@ -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, @@ -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, @@ -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, @@ -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") } @@ -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 } diff --git a/github/data_source_github_ip_ranges_test.go b/github/data_source_github_ip_ranges_test.go index b70fd61c37..27a1658bfc 100644 --- a/github/data_source_github_ip_ranges_test.go +++ b/github/data_source_github_ip_ranges_test.go @@ -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.#"), diff --git a/website/docs/d/ip_ranges.html.markdown b/website/docs/d/ip_ranges.html.markdown index 85fdc5a3d0..5bf7f75be8 100644 --- a/website/docs/d/ip_ranges.html.markdown +++ b/website/docs/d/ip_ranges.html.markdown @@ -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.