mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
d/compute_lb_ip_ranges: Add new data source
This commit is contained in:
parent
888df75f39
commit
80ca6c26b1
45
google/data_source_compute_lb_ip_ranges.go
Normal file
45
google/data_source_compute_lb_ip_ranges.go
Normal file
|
@ -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
google/data_source_compute_lb_ip_ranges_test.go
Normal file
34
google/data_source_compute_lb_ip_ranges_test.go
Normal file
|
@ -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" {}
|
||||||
|
`
|
|
@ -51,6 +51,7 @@ func Provider() terraform.ResourceProvider {
|
||||||
DataSourcesMap: map[string]*schema.Resource{
|
DataSourcesMap: map[string]*schema.Resource{
|
||||||
"google_dns_managed_zone": dataSourceDnsManagedZone(),
|
"google_dns_managed_zone": dataSourceDnsManagedZone(),
|
||||||
"google_client_config": dataSourceGoogleClientConfig(),
|
"google_client_config": dataSourceGoogleClientConfig(),
|
||||||
|
"google_compute_lb_ip_ranges": dataSourceGoogleComputeLbIpRanges(),
|
||||||
"google_compute_network": dataSourceGoogleComputeNetwork(),
|
"google_compute_network": dataSourceGoogleComputeNetwork(),
|
||||||
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
|
"google_compute_subnetwork": dataSourceGoogleComputeSubnetwork(),
|
||||||
"google_compute_zones": dataSourceGoogleComputeZones(),
|
"google_compute_zones": dataSourceGoogleComputeZones(),
|
||||||
|
|
46
website/docs/d/datasource_compute_lb_ip_ranges.html.markdown
Normal file
46
website/docs/d/datasource_compute_lb_ip_ranges.html.markdown
Normal file
|
@ -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
|
|
@ -28,6 +28,9 @@
|
||||||
<li<%= sidebar_current("docs-google-datasource-compute-instance-group") %>>
|
<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>
|
<a href="/docs/providers/google/d/google_compute_instance_group.html">google_compute_instance_group</a>
|
||||||
</li>
|
</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") %>>
|
<li<%= sidebar_current("docs-google-datasource-container-versions") %>>
|
||||||
<a href="/docs/providers/google/d/google_container_engine_versions.html">google_container_engine_versions</a>
|
<a href="/docs/providers/google/d/google_container_engine_versions.html">google_container_engine_versions</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user