-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #567 from terraform-providers/f-ds-lb-ip-ranges
d/compute_lb_ip_ranges: Add new data source
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" {} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
website/docs/d/datasource_compute_lb_ip_ranges.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters