diff --git a/build/ansible b/build/ansible index 365732a760e5..152fe2f7ef03 160000 --- a/build/ansible +++ b/build/ansible @@ -1 +1 @@ -Subproject commit 365732a760e5d90c496752196c35297eda5259d3 +Subproject commit 152fe2f7ef03501cd440f6043aaf75754661dcfe diff --git a/build/chef/compute b/build/chef/compute index 214100a24a95..7ceba323c8bd 160000 --- a/build/chef/compute +++ b/build/chef/compute @@ -1 +1 @@ -Subproject commit 214100a24a95a05396613285f37645971d5dd9d2 +Subproject commit 7ceba323c8bdad66d542647c8338544c7316e8cf diff --git a/build/puppet/compute b/build/puppet/compute index 875a5bffe09d..67ab3b2d1fe2 160000 --- a/build/puppet/compute +++ b/build/puppet/compute @@ -1 +1 @@ -Subproject commit 875a5bffe09d731c468e91ea0748be1d958dbbe6 +Subproject commit 67ab3b2d1fe2007b9d8b619cfbce0dca3bfb3836 diff --git a/build/terraform b/build/terraform index 6969ce5b4e11..35e6885c7538 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 6969ce5b4e11206f2a7441becf373add86828dc4 +Subproject commit 35e6885c75383ce122f45f5575b0df5777fac74d diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 383110a6fa7d..753199afb4b6 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -3868,11 +3868,12 @@ objects: imports: 'selfLink' input: true required: true - # TODO(ndmckinley): Make this a resource refefence - - !ruby/object:Api::Type::String + - !ruby/object:Api::Type::ResourceRef name: 'router' description: | URL of router resource to be used for dynamic routing. + resource: 'Router' + imports: 'selfLink' input: true - !ruby/object:Api::Type::String name: 'peerIp' diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index 76232dabc883..516f5da4c6b6 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -1247,8 +1247,7 @@ overrides: !ruby/object:Provider::ResourceOverrides labelFingerprint: !ruby/object:Provider::Terraform::PropertyOverride exclude: false router: !ruby/object:Provider::Terraform::PropertyOverride - custom_expand: 'templates/terraform/custom_expand/router_link.erb' - custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' + custom_expand: 'templates/terraform/custom_expand/compute_full_url.erb' custom_code: !ruby/object:Provider::Terraform::CustomCode constants: templates/terraform/constants/vpn_tunnel.erb Zone: !ruby/object:Provider::Terraform::ResourceOverride @@ -1286,6 +1285,8 @@ files: !ruby/object:Provider::Config::Files 'templates/terraform/tests/resource_compute_target_https_proxy_test.go' 'google/resource_compute_target_ssl_proxy_test.go': 'templates/terraform/tests/resource_compute_target_ssl_proxy_test.go' + 'google/resource_compute_vpn_tunnel_test.go': + 'templates/terraform/tests/resource_compute_vpn_tunnel_test.go' # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: diff --git a/templates/terraform/custom_expand/compute_full_url.erb b/templates/terraform/custom_expand/compute_full_url.erb index c0dc631482a8..b57c8f3c4574 100644 --- a/templates/terraform/custom_expand/compute_full_url.erb +++ b/templates/terraform/custom_expand/compute_full_url.erb @@ -13,6 +13,9 @@ # limitations under the License. <% end -%> func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + if v == nil || v.(string) == "" { + return "", nil + } f, err := <%= build_expand_resource_ref('v.(string)', property) %> if err != nil { return nil, fmt.Errorf("Invalid value for <%= property.name.underscore -%>: %s", err) diff --git a/templates/terraform/custom_expand/router_link.erb b/templates/terraform/custom_expand/router_link.erb deleted file mode 100644 index 82f8ca05c9bb..000000000000 --- a/templates/terraform/custom_expand/router_link.erb +++ /dev/null @@ -1,24 +0,0 @@ -<% if false # the license inside this if block pertains to this file -%> - # Copyright 2017 Google Inc. - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. -<% end -%> -func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { - if v == nil || v.(string) == "" { - return "", nil - } - f, err := parseRegionalFieldValue("routers", v.(string), "project", "region", "zone", d, config, true) - if err != nil { - return nil, fmt.Errorf("Invalid value for <%= Google::StringUtils.underscore(property.name) -%>: %s", err) - } - return "https://www.googleapis.com/compute/v1/" + f.RelativeLink(), nil -} diff --git a/templates/terraform/tests/resource_compute_vpn_tunnel_test.go b/templates/terraform/tests/resource_compute_vpn_tunnel_test.go new file mode 100644 index 000000000000..a363942a3607 --- /dev/null +++ b/templates/terraform/tests/resource_compute_vpn_tunnel_test.go @@ -0,0 +1,269 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + + "google.golang.org/api/compute/v1" +) + +func TestAccComputeVpnTunnel_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeVpnTunnelDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeVpnTunnel_basic(), + }, + resource.TestStep{ + ResourceName: "google_compute_vpn_tunnel.foobar", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"shared_secret"}, + }, + }, + }) +} + +func TestAccComputeVpnTunnel_router(t *testing.T) { + t.Parallel() + + router := fmt.Sprintf("tunnel-test-router-%s", acctest.RandString(10)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeVpnTunnelDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeVpnTunnelRouter(router), + }, + resource.TestStep{ + ResourceName: "google_compute_vpn_tunnel.foobar", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"shared_secret"}, + }, + }, + }) +} + +func TestAccComputeVpnTunnel_defaultTrafficSelectors(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeVpnTunnelDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeVpnTunnelDefaultTrafficSelectors(), + }, + resource.TestStep{ + ResourceName: "google_compute_vpn_tunnel.foobar", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"shared_secret"}, + }, + }, + }) +} + +func testAccCheckComputeVpnTunnelDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + project := config.Project + + vpnTunnelsService := compute.NewVpnTunnelsService(config.clientCompute) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "google_compute_network" { + continue + } + + region := rs.Primary.Attributes["region"] + name := rs.Primary.Attributes["name"] + + _, err := vpnTunnelsService.Get(project, region, name).Do() + + if err == nil { + return fmt.Errorf("Error, VPN Tunnel %s in region %s still exists", + name, region) + } + } + + return nil +} + +func testAccComputeVpnTunnel_basic() string { + return fmt.Sprintf(` +resource "google_compute_network" "foobar" { + name = "tunnel-test-%s" +} +resource "google_compute_subnetwork" "foobar" { + name = "tunnel-test-subnetwork-%s" + network = "${google_compute_network.foobar.self_link}" + ip_cidr_range = "10.0.0.0/16" + region = "us-central1" +} +resource "google_compute_address" "foobar" { + name = "tunnel-test-%s" + region = "${google_compute_subnetwork.foobar.region}" +} +resource "google_compute_vpn_gateway" "foobar" { + name = "tunnel-test-%s" + network = "${google_compute_network.foobar.self_link}" + region = "${google_compute_subnetwork.foobar.region}" +} +resource "google_compute_forwarding_rule" "foobar_esp" { + name = "tunnel-test-%s" + region = "${google_compute_vpn_gateway.foobar.region}" + ip_protocol = "ESP" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" +} +resource "google_compute_forwarding_rule" "foobar_udp500" { + name = "tunnel-test-%s" + region = "${google_compute_forwarding_rule.foobar_esp.region}" + ip_protocol = "UDP" + port_range = "500-500" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" +} +resource "google_compute_forwarding_rule" "foobar_udp4500" { + name = "tunnel-test-%s" + region = "${google_compute_forwarding_rule.foobar_udp500.region}" + ip_protocol = "UDP" + port_range = "4500-4500" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" +} +resource "google_compute_vpn_tunnel" "foobar" { + name = "tunnel-test-%s" + region = "${google_compute_forwarding_rule.foobar_udp4500.region}" + target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}" + shared_secret = "unguessable" + peer_ip = "8.8.8.8" + local_traffic_selector = ["${google_compute_subnetwork.foobar.ip_cidr_range}"] + remote_traffic_selector = ["192.168.0.0/24", "192.168.1.0/24"] +}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), + acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), + acctest.RandString(10), acctest.RandString(10)) +} + +func testAccComputeVpnTunnelRouter(router string) string { + testId := acctest.RandString(10) + return fmt.Sprintf(` + resource "google_compute_network" "foobar" { + name = "tunnel-test-%s" + } + resource "google_compute_subnetwork" "foobar" { + name = "tunnel-test-subnetwork-%s" + network = "${google_compute_network.foobar.self_link}" + ip_cidr_range = "10.0.0.0/16" + region = "us-central1" + } + resource "google_compute_address" "foobar" { + name = "tunnel-test-%s" + region = "${google_compute_subnetwork.foobar.region}" + } + resource "google_compute_vpn_gateway" "foobar" { + name = "tunnel-test-%s" + network = "${google_compute_network.foobar.self_link}" + region = "${google_compute_subnetwork.foobar.region}" + } + resource "google_compute_forwarding_rule" "foobar_esp" { + name = "tunnel-test-%s-1" + region = "${google_compute_vpn_gateway.foobar.region}" + ip_protocol = "ESP" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" + } + resource "google_compute_forwarding_rule" "foobar_udp500" { + name = "tunnel-test-%s-2" + region = "${google_compute_forwarding_rule.foobar_esp.region}" + ip_protocol = "UDP" + port_range = "500-500" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" + } + resource "google_compute_forwarding_rule" "foobar_udp4500" { + name = "tunnel-test-%s-3" + region = "${google_compute_forwarding_rule.foobar_udp500.region}" + ip_protocol = "UDP" + port_range = "4500-4500" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" + } + resource "google_compute_router" "foobar"{ + name = "%s" + region = "${google_compute_forwarding_rule.foobar_udp500.region}" + network = "${google_compute_network.foobar.self_link}" + bgp { + asn = 64514 + } + } + resource "google_compute_vpn_tunnel" "foobar" { + name = "tunnel-test-%s" + region = "${google_compute_forwarding_rule.foobar_udp4500.region}" + target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}" + shared_secret = "unguessable" + peer_ip = "8.8.8.8" + router = "${google_compute_router.foobar.self_link}" + } + `, testId, testId, testId, testId, testId, testId, testId, router, testId) +} + +func testAccComputeVpnTunnelDefaultTrafficSelectors() string { + return fmt.Sprintf(` +resource "google_compute_network" "foobar" { + name = "tunnel-test-%s" + auto_create_subnetworks = "true" +} +resource "google_compute_address" "foobar" { + name = "tunnel-test-%s" + region = "us-central1" +} +resource "google_compute_vpn_gateway" "foobar" { + name = "tunnel-test-%s" + network = "${google_compute_network.foobar.self_link}" + region = "${google_compute_address.foobar.region}" +} +resource "google_compute_forwarding_rule" "foobar_esp" { + name = "tunnel-test-%s" + region = "${google_compute_vpn_gateway.foobar.region}" + ip_protocol = "ESP" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" +} +resource "google_compute_forwarding_rule" "foobar_udp500" { + name = "tunnel-test-%s" + region = "${google_compute_forwarding_rule.foobar_esp.region}" + ip_protocol = "UDP" + port_range = "500-500" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" +} +resource "google_compute_forwarding_rule" "foobar_udp4500" { + name = "tunnel-test-%s" + region = "${google_compute_forwarding_rule.foobar_udp500.region}" + ip_protocol = "UDP" + port_range = "4500-4500" + ip_address = "${google_compute_address.foobar.address}" + target = "${google_compute_vpn_gateway.foobar.self_link}" +} +resource "google_compute_vpn_tunnel" "foobar" { + name = "tunnel-test-%s" + region = "${google_compute_forwarding_rule.foobar_udp4500.region}" + target_vpn_gateway = "${google_compute_vpn_gateway.foobar.self_link}" + shared_secret = "unguessable" + peer_ip = "8.8.8.8" +}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), + acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), + acctest.RandString(10)) +}