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

Direct google access #7651

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
3 changes: 3 additions & 0 deletions .changelog/4034.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `private_ipv6_google_access` field to `google_compute_subnetwork`
```
57 changes: 57 additions & 0 deletions google/resource_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ Can only be specified if VPC flow logs for this subnetwork is enabled and "metad
Description: `When enabled, VMs in this subnetwork without external IP addresses can
access Google APIs and services by using Private Google Access.`,
},
"private_ipv6_google_access": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `The private IPv6 google access type for the VMs in this subnet.`,
},
"region": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -340,6 +346,12 @@ func resourceComputeSubnetworkCreate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("private_ip_google_access"); !isEmptyValue(reflect.ValueOf(privateIpGoogleAccessProp)) && (ok || !reflect.DeepEqual(v, privateIpGoogleAccessProp)) {
obj["privateIpGoogleAccess"] = privateIpGoogleAccessProp
}
privateIpv6GoogleAccessProp, err := expandComputeSubnetworkPrivateIpv6GoogleAccess(d.Get("private_ipv6_google_access"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("private_ipv6_google_access"); !isEmptyValue(reflect.ValueOf(privateIpv6GoogleAccessProp)) && (ok || !reflect.DeepEqual(v, privateIpv6GoogleAccessProp)) {
obj["privateIpv6GoogleAccess"] = privateIpv6GoogleAccessProp
}
regionProp, err := expandComputeSubnetworkRegion(d.Get("region"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -457,6 +469,9 @@ func resourceComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("private_ip_google_access", flattenComputeSubnetworkPrivateIpGoogleAccess(res["privateIpGoogleAccess"], d, config)); err != nil {
return fmt.Errorf("Error reading Subnetwork: %s", err)
}
if err := d.Set("private_ipv6_google_access", flattenComputeSubnetworkPrivateIpv6GoogleAccess(res["privateIpv6GoogleAccess"], d, config)); err != nil {
return fmt.Errorf("Error reading Subnetwork: %s", err)
}
if err := d.Set("region", flattenComputeSubnetworkRegion(res["region"], d, config)); err != nil {
return fmt.Errorf("Error reading Subnetwork: %s", err)
}
Expand Down Expand Up @@ -555,6 +570,40 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e
return err
}
}
if d.HasChange("private_ipv6_google_access") {
obj := make(map[string]interface{})

privateIpv6GoogleAccessProp, err := expandComputeSubnetworkPrivateIpv6GoogleAccess(d.Get("private_ipv6_google_access"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("private_ipv6_google_access"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, privateIpv6GoogleAccessProp)) {
obj["privateIpv6GoogleAccess"] = privateIpv6GoogleAccessProp
}

url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
if err != nil {
return err
}

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("Error updating Subnetwork %q: %s", d.Id(), err)
} else {
log.Printf("[DEBUG] Finished updating Subnetwork %q: %#v", d.Id(), res)
}

err = computeOperationWaitTime(
config, res, project, "Updating Subnetwork", userAgent,
d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}
}
if d.HasChange("log_config") {
obj := make(map[string]interface{})

Expand Down Expand Up @@ -787,6 +836,10 @@ func flattenComputeSubnetworkPrivateIpGoogleAccess(v interface{}, d *schema.Reso
return v
}

func flattenComputeSubnetworkPrivateIpv6GoogleAccess(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenComputeSubnetworkRegion(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -888,6 +941,10 @@ func expandComputeSubnetworkPrivateIpGoogleAccess(v interface{}, d TerraformReso
return v, nil
}

func expandComputeSubnetworkPrivateIpv6GoogleAccess(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeSubnetworkRegion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/compute_subnetwork.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ The following arguments are supported:
When enabled, VMs in this subnetwork without external IP addresses can
access Google APIs and services by using Private Google Access.

* `private_ipv6_google_access` -
(Optional)
The private IPv6 google access type for the VMs in this subnet.

* `region` -
(Optional)
The GCP region for this subnetwork.
Expand Down