diff --git a/google-beta/resource_compute_vpn_tunnel.go b/google-beta/resource_compute_vpn_tunnel.go index d14a8cc87f9..7500696f30f 100644 --- a/google-beta/resource_compute_vpn_tunnel.go +++ b/google-beta/resource_compute_vpn_tunnel.go @@ -326,6 +326,11 @@ func resourceComputeVpnTunnelCreate(d *schema.ResourceData, meta interface{}) er obj["region"] = regionProp } + obj, err = resourceComputeVpnTunnelEncoder(d, meta, obj) + if err != nil { + return err + } + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/vpnTunnels") if err != nil { return err @@ -694,3 +699,18 @@ func expandComputeVpnTunnelRegion(v interface{}, d *schema.ResourceData, config } return f.RelativeLink(), nil } + +func resourceComputeVpnTunnelEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { + config := meta.(*Config) + f, err := parseRegionalFieldValue("targetVpnGateways", d.Get("target_vpn_gateway").(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, err + } + if _, ok := d.GetOk("project"); !ok { + d.Set("project", f.Project) + } + if _, ok := d.GetOk("region"); !ok { + d.Set("region", f.Region) + } + return obj, nil +} diff --git a/website/docs/r/compute_vpn_tunnel.html.markdown b/website/docs/r/compute_vpn_tunnel.html.markdown index 05df2a91209..f7b1aa033ae 100644 --- a/website/docs/r/compute_vpn_tunnel.html.markdown +++ b/website/docs/r/compute_vpn_tunnel.html.markdown @@ -171,7 +171,7 @@ The following arguments are supported: * `region` - (Optional) - The region where the tunnel is located. + The region where the tunnel is located. If unset, is set to the region of `target_vpn_gateway`. * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.