Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add secondary range support to google_compute_subnetwork data source #687

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions google/data_source_google_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"secondary_ip_range": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"range_name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"ip_cidr_range": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
},
},
"network": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand All @@ -43,11 +59,13 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
},
"region": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Optional: true,
},

"project": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Optional: true,
},
},
Expand Down Expand Up @@ -84,6 +102,10 @@ func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interfac
d.Set("description", subnetwork.Description)
d.Set("gateway_address", subnetwork.GatewayAddress)
d.Set("network", subnetwork.Network)
d.Set("project", project)
d.Set("region", region)
// Flattening code defined in resource_compute_subnetwork.go
d.Set("secondary_ip_range", flattenSecondaryRanges(subnetwork.SecondaryIpRanges))

//Subnet id creation is defined in resource_compute_subnetwork.go
subnetwork.Region = region
Expand Down
5 changes: 5 additions & 0 deletions google/data_source_google_compute_subnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func testAccDataSourceGoogleSubnetworkCheck(data_source_name string, resource_na
"ip_cidr_range",
"network",
"private_ip_google_access",
"secondary_ip_range",
}

for _, attr_to_check := range subnetwork_attrs_to_test {
Expand Down Expand Up @@ -77,6 +78,10 @@ resource "google_compute_subnetwork" "foobar" {
ip_cidr_range = "10.0.0.0/24"
network = "${google_compute_network.foobar.self_link}"
private_ip_google_access = true
secondary_ip_range {
range_name = "tf-test-secondary-range"
ip_cidr_range = "192.168.1.0/24"
}
}

data "google_compute_subnetwork" "my_subnetwork" {
Expand Down
11 changes: 11 additions & 0 deletions website/docs/d/datasource_compute_subnetwork.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,15 @@ In addition to the arguments listed above, the following attributes are exported
can access Google services without assigned external IP
addresses.

* `secondary_ip_range` - An array of configurations for secondary IP ranges for
VM instances contained in this subnetwork. Structure is documented below.

* `self_link` - The URI of the created resource.

The `secondary_ip_range` block supports:

* `range_name` - The name associated with this subnetwork secondary range, used
when adding an alias IP range to a VM instance.

* `ip_cidr_range` - The range of IP addresses belonging to this subnetwork
secondary range.