Skip to content

Commit 577a4c0

Browse files
author
Nic Cope
committed
Add secondary range support to google_compute_subnetwork data source
..and throw in project and region while we're at it.
1 parent b74e1cd commit 577a4c0

3 files changed

+38
-0
lines changed

google/data_source_google_compute_subnetwork.go

+22
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
3333
Type: schema.TypeBool,
3434
Computed: true,
3535
},
36+
"secondary_ip_range": &schema.Schema{
37+
Type: schema.TypeList,
38+
Computed: true,
39+
Elem: &schema.Resource{
40+
Schema: map[string]*schema.Schema{
41+
"range_name": &schema.Schema{
42+
Type: schema.TypeString,
43+
Computed: true,
44+
},
45+
"ip_cidr_range": &schema.Schema{
46+
Type: schema.TypeString,
47+
Computed: true,
48+
},
49+
},
50+
},
51+
},
3652
"network": &schema.Schema{
3753
Type: schema.TypeString,
3854
Computed: true,
@@ -43,11 +59,13 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
4359
},
4460
"region": &schema.Schema{
4561
Type: schema.TypeString,
62+
Computed: true,
4663
Optional: true,
4764
},
4865

4966
"project": &schema.Schema{
5067
Type: schema.TypeString,
68+
Computed: true,
5169
Optional: true,
5270
},
5371
},
@@ -84,6 +102,10 @@ func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interfac
84102
d.Set("description", subnetwork.Description)
85103
d.Set("gateway_address", subnetwork.GatewayAddress)
86104
d.Set("network", subnetwork.Network)
105+
d.Set("project", project)
106+
d.Set("region", region)
107+
// Flattening code defined in resource_compute_subnetwork.go
108+
d.Set("secondary_ip_range", flattenSecondaryRanges(subnetwork.SecondaryIpRanges))
87109

88110
//Subnet id creation is defined in resource_compute_subnetwork.go
89111
subnetwork.Region = region

google/data_source_google_compute_subnetwork_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func testAccDataSourceGoogleSubnetworkCheck(data_source_name string, resource_na
4848
"ip_cidr_range",
4949
"network",
5050
"private_ip_google_access",
51+
"secondary_ip_range",
5152
}
5253

5354
for _, attr_to_check := range subnetwork_attrs_to_test {
@@ -77,6 +78,10 @@ resource "google_compute_subnetwork" "foobar" {
7778
ip_cidr_range = "10.0.0.0/24"
7879
network = "${google_compute_network.foobar.self_link}"
7980
private_ip_google_access = true
81+
secondary_ip_range {
82+
range_name = "tf-test-secondary-range"
83+
ip_cidr_range = "192.168.1.0/24"
84+
}
8085
}
8186
8287
data "google_compute_subnetwork" "my_subnetwork" {

website/docs/d/datasource_compute_subnetwork.html.markdown

+11
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,15 @@ In addition to the arguments listed above, the following attributes are exported
5151
can access Google services without assigned external IP
5252
addresses.
5353

54+
* `secondary_ip_range` - An array of configurations for secondary IP ranges for
55+
VM instances contained in this subnetwork. Structure is documented below.
56+
5457
* `self_link` - The URI of the created resource.
58+
59+
The `secondary_ip_range` block supports:
60+
61+
* `range_name` - The name associated with this subnetwork secondary range, used
62+
when adding an alias IP range to a VM instance.
63+
64+
* `ip_cidr_range` - The range of IP addresses belonging to this subnetwork
65+
secondary range.

0 commit comments

Comments
 (0)