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

Store vpn_tunnel.router as a self_link. Fixes #1963. #2003

Merged
merged 1 commit into from
Sep 7, 2018
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 google/resource_compute_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ func expandComputeAutoscalerAutoscalingPolicyLoadBalancingUtilizationTarget(v in
}

func expandComputeAutoscalerTarget(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
if v == nil || v.(string) == "" {
return "", nil
}
f, err := parseZonalFieldValue("instanceGroupManagers", v.(string), "project", "zone", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for target: %s", err)
Expand Down
9 changes: 5 additions & 4 deletions google/resource_compute_vpn_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ func resourceComputeVpnTunnel() *schema.Resource {
ForceNew: true,
},
"router": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"ike_version": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -557,7 +558,7 @@ func flattenComputeVpnTunnelRouter(v interface{}) interface{} {
if v == nil {
return v
}
return NameFromSelfLinkStateFunc(v)
return ConvertSelfLinkToV1(v.(string))
}

func flattenComputeVpnTunnelPeerIp(v interface{}) interface{} {
Expand Down
63 changes: 19 additions & 44 deletions google/resource_compute_vpn_tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ func TestAccComputeVpnTunnel_basic(t *testing.T) {
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeVpnTunnel_basic(),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeVpnTunnelExists(
"google_compute_vpn_tunnel.foobar"),
resource.TestCheckResourceAttr(
"google_compute_vpn_tunnel.foobar", "local_traffic_selector.#", "1"),
resource.TestCheckResourceAttr(
"google_compute_vpn_tunnel.foobar", "remote_traffic_selector.#", "2"),
),
},
resource.TestStep{
ResourceName: "google_compute_vpn_tunnel.foobar",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"shared_secret"},
},
},
})
Expand All @@ -45,12 +43,12 @@ func TestAccComputeVpnTunnel_router(t *testing.T) {
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeVpnTunnelRouter(router),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeVpnTunnelExists(
"google_compute_vpn_tunnel.foobar"),
resource.TestCheckResourceAttr(
"google_compute_vpn_tunnel.foobar", "router", router),
),
},
resource.TestStep{
ResourceName: "google_compute_vpn_tunnel.foobar",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"shared_secret"},
},
},
})
Expand All @@ -66,8 +64,12 @@ func TestAccComputeVpnTunnel_defaultTrafficSelectors(t *testing.T) {
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeVpnTunnelDefaultTrafficSelectors(),
Check: testAccCheckComputeVpnTunnelExists(
"google_compute_vpn_tunnel.foobar"),
},
resource.TestStep{
ResourceName: "google_compute_vpn_tunnel.foobar",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"shared_secret"},
},
},
})
Expand Down Expand Up @@ -98,33 +100,6 @@ func testAccCheckComputeVpnTunnelDestroy(s *terraform.State) error {
return nil
}

func testAccCheckComputeVpnTunnelExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}

config := testAccProvider.Meta().(*Config)
name := rs.Primary.Attributes["name"]
region := rs.Primary.Attributes["region"]
project := config.Project

vpnTunnelsService := compute.NewVpnTunnelsService(config.clientCompute)
_, err := vpnTunnelsService.Get(project, region, name).Do()

if err != nil {
return fmt.Errorf("Error Reading VPN Tunnel %s: %s", name, err)
}

return nil
}
}

func testAccComputeVpnTunnel_basic() string {
return fmt.Sprintf(`
resource "google_compute_network" "foobar" {
Expand Down Expand Up @@ -239,7 +214,7 @@ func testAccComputeVpnTunnelRouter(router string) string {
target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}"
shared_secret = "unguessable"
peer_ip = "8.8.8.8"
router = "${google_compute_router.foobar.name}"
router = "${google_compute_router.foobar.self_link}"
}
`, testId, testId, testId, testId, testId, testId, testId, router, testId)
}
Expand Down