From 1fc23a0d709f78c8280b7a3620a77bb5b87538a4 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Wed, 12 Dec 2018 00:07:30 +0000 Subject: [PATCH] extract vpn tunnel region/project from vpn gateway --- google-beta/resource_compute_vpn_tunnel.go | 20 +++++++++++++++++++ .../docs/r/compute_vpn_tunnel.html.markdown | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) 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.