Skip to content

Commit

Permalink
private-googleapis data source support
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
drebes authored and modular-magician committed Sep 19, 2019
1 parent ce8fae1 commit 03dfd06
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 7 additions & 1 deletion google/data_source_google_netblock_ip_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ func dataSourceGoogleNetblockIpRangesRead(d *schema.ResourceData, meta interface
d.Set("cidr_blocks_ipv6", CidrBlocks["cidr_blocks_ipv6"])
// Static ranges
case "restricted-googleapis":
// https://cloud.google.com/vpc/docs/configure-private-google-access-hybrid
// https://cloud.google.com/vpc/docs/private-access-options#domain-vips
CidrBlocks["cidr_blocks_ipv4"] = append(CidrBlocks["cidr_blocks_ipv4"], "199.36.153.4/30")
CidrBlocks["cidr_blocks"] = CidrBlocks["cidr_blocks_ipv4"]
d.Set("cidr_blocks", CidrBlocks["cidr_blocks"])
d.Set("cidr_blocks_ipv4", CidrBlocks["cidr_blocks_ipv4"])
case "private-googleapis":
// https://cloud.google.com/vpc/docs/private-access-options#domain-vips
CidrBlocks["cidr_blocks_ipv4"] = append(CidrBlocks["cidr_blocks_ipv4"], "199.36.153.8/30")
CidrBlocks["cidr_blocks"] = CidrBlocks["cidr_blocks_ipv4"]
d.Set("cidr_blocks", CidrBlocks["cidr_blocks"])
d.Set("cidr_blocks_ipv4", CidrBlocks["cidr_blocks_ipv4"])
case "dns-forwarders":
// https://cloud.google.com/dns/zones/#creating-forwarding-zones
CidrBlocks["cidr_blocks_ipv4"] = append(CidrBlocks["cidr_blocks_ipv4"], "35.199.192.0/19")
Expand Down
19 changes: 19 additions & 0 deletions google/data_source_google_netblock_ip_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ func TestAccDataSourceGoogleNetblockIpRanges_basic(t *testing.T) {
resource.TestCheckResourceAttr("data.google_netblock_ip_ranges.restricted", "cidr_blocks_ipv6.#", "0"),
),
},
{
Config: testAccNetblockIpRangesConfig_private,
Check: resource.ComposeTestCheckFunc(
// Private Google Access Unrestricted VIP
resource.TestCheckResourceAttr("data.google_netblock_ip_ranges.private", "cidr_blocks.#", "1"),
resource.TestMatchResourceAttr("data.google_netblock_ip_ranges.private",
"cidr_blocks.0", regexp.MustCompile("^(?:[0-9a-fA-F./:]{1,4}){1,2}.*/[0-9]{1,3}$")),
resource.TestCheckResourceAttr("data.google_netblock_ip_ranges.private", "cidr_blocks_ipv4.#", "1"),
resource.TestMatchResourceAttr("data.google_netblock_ip_ranges.private",
"cidr_blocks_ipv4.0", regexp.MustCompile("^(?:[0-9]{1,3}.){3}[0-9]{1,3}/[0-9]{1,2}$")),
resource.TestCheckResourceAttr("data.google_netblock_ip_ranges.private", "cidr_blocks_ipv6.#", "0"),
),
},
{
Config: testAccNetblockIpRangesConfig_dns,
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -133,6 +146,12 @@ data "google_netblock_ip_ranges" "restricted" {
}
`

const testAccNetblockIpRangesConfig_private = `
data "google_netblock_ip_ranges" "private" {
range_type = "private-googleapis"
}
`

const testAccNetblockIpRangesConfig_dns = `
data "google_netblock_ip_ranges" "dns" {
range_type = "dns-forwarders"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ The following arguments are supported:

* `google-netblocks` - Corresponds to IP addresses used for Google services. [More details.](https://support.google.com/a/answer/33786?hl=en)

* `restricted-googleapis` - Corresponds to the IP addresses used for Private Google Access and/or VPC Service Controls API access. [More details.](https://cloud.google.com/vpc/docs/configure-private-google-access-hybrid)
* `restricted-googleapis` - Corresponds to the IP addresses used for Private Google Access only for services that support VPC Service Controls API access. [More details.](https://cloud.google.com/vpc/docs/private-access-options#domain-vips)

* `private-googleapis` - Corresponds to the IP addresses used for Private Google Access for services that do not support VPC Service Controls. [More details.](https://cloud.google.com/vpc/docs/private-access-options#domain-vips)

* `dns-forwarders` - Corresponds to the IP addresses used to originate Cloud DNS outbound forwarding. [More details.](https://cloud.google.com/dns/zones/#creating-forwarding-zones)

Expand Down

0 comments on commit 03dfd06

Please sign in to comment.