Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
provider/google: Add support for privateIpGoogleAccess on subnetworks (
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt authored and danawillow committed May 18, 2017
1 parent 208199a commit 27927dd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func dataSourceGoogleComputeSubnetwork() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"private_ip_google_access": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
},
"network": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -75,6 +79,7 @@ func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interfac
}

d.Set("ip_cidr_range", subnetwork.IpCidrRange)
d.Set("private_ip_google_access", subnetwork.PrivateIpGoogleAccess)
d.Set("self_link", subnetwork.SelfLink)
d.Set("description", subnetwork.Description)
d.Set("gateway_address", subnetwork.GatewayAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func testAccDataSourceGoogleSubnetworkCheck(data_source_name string, resource_na
"description",
"ip_cidr_range",
"network",
"private_ip_google_access",
}

for _, attr_to_check := range subnetwork_attrs_to_test {
Expand Down Expand Up @@ -73,6 +74,7 @@ resource "google_compute_subnetwork" "foobar" {
description = "my-description"
ip_cidr_range = "10.0.0.0/24"
network = "${google_compute_network.foobar.self_link}"
private_ip_google_access = true
}
data "google_compute_subnetwork" "my_subnetwork" {
Expand Down
15 changes: 11 additions & 4 deletions builtin/providers/google/resource_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func resourceComputeSubnetwork() *schema.Resource {
ForceNew: true,
},

"private_ip_google_access": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},

"self_link": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -97,10 +103,11 @@ func resourceComputeSubnetworkCreate(d *schema.ResourceData, meta interface{}) e

// Build the subnetwork parameters
subnetwork := &compute.Subnetwork{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
IpCidrRange: d.Get("ip_cidr_range").(string),
Network: network,
Name: d.Get("name").(string),
Description: d.Get("description").(string),
IpCidrRange: d.Get("ip_cidr_range").(string),
PrivateIpGoogleAccess: d.Get("private_ip_google_access").(bool),
Network: network,
}

log.Printf("[DEBUG] Subnetwork insert request: %#v", subnetwork)
Expand Down
10 changes: 9 additions & 1 deletion builtin/providers/google/resource_compute_subnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ resource "google_compute_subnetwork" "network-ref-by-name" {
network = "${google_compute_network.custom-test.name}"
}
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
resource "google_compute_subnetwork" "network-with-private-google-access" {
name = "subnetwork-test-%s"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = "${google_compute_network.custom-test.self_link}"
private_ip_google_access = true
}
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The following arguments are supported:
In addition to the arguments listed above, the following attributes are exported:

* `network` - The network name or resource link to the parent
network of this subnetwork.
network of this subnetwork.

* `description` - Description of this subnetwork.

Expand All @@ -47,4 +47,8 @@ In addition to the arguments listed above, the following attributes are exported

* `gateway_address` - The IP address of the gateway.

* `private_ip_google_access` - Whether the VMs in this subnet
can access Google services without assigned external IP
addresses.

* `self_link` - The URI of the created resource.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ The following arguments are supported:
* `region` - (Optional) The region this subnetwork will be created in. If
unspecified, this defaults to the region configured in the provider.

* `private_ip_google_access` - Whether the VMs in this subnet
can access Google services without assigned external IP
addresses.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are
Expand Down

0 comments on commit 27927dd

Please sign in to comment.