Skip to content

Commit

Permalink
Merge pull request #567 from terraform-providers/f-ds-lb-ip-ranges
Browse files Browse the repository at this point in the history
d/compute_lb_ip_ranges: Add new data source
  • Loading branch information
radeksimko authored Oct 13, 2017
2 parents b300c65 + 80ca6c2 commit 25869fa
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
45 changes: 45 additions & 0 deletions google/data_source_compute_lb_ip_ranges.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package google

import (
"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceGoogleComputeLbIpRanges() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleComputeLbIpRangesRead,

Schema: map[string]*schema.Schema{
"network": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"http_ssl_tcp_internal": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
},
}
}

func dataSourceGoogleComputeLbIpRangesRead(d *schema.ResourceData, meta interface{}) error {
d.SetId("compute-lb-ip-ranges")

// https://cloud.google.com/compute/docs/load-balancing/health-checks#health_check_source_ips_and_firewall_rules

networkIpRanges := []string{
"209.85.152.0/22",
"209.85.204.0/22",
"35.191.0.0/16",
}
d.Set("network", networkIpRanges)

httpSslTcpInternalRanges := []string{
"130.211.0.0/22",
"35.191.0.0/16",
}
d.Set("http_ssl_tcp_internal", httpSslTcpInternalRanges)

return nil
}
34 changes: 34 additions & 0 deletions google/data_source_compute_lb_ip_ranges_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package google

import (
"regexp"
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceComputeLbIpRanges_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeLbIpRangesConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("data.google_compute_lb_ip_ranges.some",
"network.#", regexp.MustCompile("^[1-9]+[0-9]*$")),
resource.TestMatchResourceAttr("data.google_compute_lb_ip_ranges.some",
"network.0", regexp.MustCompile("^[0-9./]+$")),
resource.TestMatchResourceAttr("data.google_compute_lb_ip_ranges.some",
"http_ssl_tcp_internal.#", regexp.MustCompile("^[1-9]+[0-9]*$")),
resource.TestMatchResourceAttr("data.google_compute_lb_ip_ranges.some",
"http_ssl_tcp_internal.0", regexp.MustCompile("^[0-9./]+$")),
),
},
},
})
}

const testAccComputeLbIpRangesConfig = `
data "google_compute_lb_ip_ranges" "some" {}
`
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Provider() terraform.ResourceProvider {
DataSourcesMap: map[string]*schema.Resource{
"google_dns_managed_zone": dataSourceDnsManagedZone(),
"google_client_config": dataSourceGoogleClientConfig(),
"google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(),
"google_compute_network": dataSourceGoogleComputeNetwork(),
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
"google_compute_zones": dataSourceGoogleComputeZones(),
Expand Down
46 changes: 46 additions & 0 deletions website/docs/d/datasource_compute_lb_ip_ranges.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
layout: "google"
page_title: "Google: google_compute_lb_ip_ranges"
sidebar_current: "docs-google-datasource-compute-lb-ip-ranges"
description: |-
Get information about the IP ranges used when health-checking load balancers.
---

# google_compute_lb_ip_ranges

Use this data source to access IP ranges in your firewall rules.

https://cloud.google.com/compute/docs/load-balancing/health-checks#health_check_source_ips_and_firewall_rules

## Example Usage

```tf
data "google_compute_lb_ip_ranges" "ranges" {}
resource "google_compute_firewall" "lb" {
name = "lb-firewall"
network = "${google_compute_network.main.name}"
allow {
protocol = "tcp"
ports = ["80"]
}
source_ranges = ["${data.google_compute_lb_ip_ranges.ranges.network}"]
target_tags = [
"InstanceBehindLoadBalancer"
]
}
```

## Argument Reference

There are no arguments available for this data source.

## Attributes Reference

In addition to the arguments listed above, the following attributes are exported:

* `network` - The IP ranges used for health checks when **Network load balancing** is used

* `http_ssl_tcp_internal` - The IP ranges used for health checks when **HTTP(S), SSL proxy, TCP proxy, and Internal load balancing** is used
3 changes: 3 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<li<%= sidebar_current("docs-google-datasource-compute-instance-group") %>>
<a href="/docs/providers/google/d/google_compute_instance_group.html">google_compute_instance_group</a>
</li>
<li<%= sidebar_current("docs-google-datasource-compute-lb-ip-ranges") %>>
<a href="/docs/providers/google/d/google_compute_lb_ip_ranges.html">google_compute_lb_ip_ranges</a>
</li>
<li<%= sidebar_current("docs-google-datasource-container-versions") %>>
<a href="/docs/providers/google/d/google_container_engine_versions.html">google_container_engine_versions</a>
</li>
Expand Down

0 comments on commit 25869fa

Please sign in to comment.