From 3738eca35c3dc8ea64d8d76a2ac6af5752116dba Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Mon, 2 Jul 2018 16:46:19 -0700 Subject: [PATCH] add router resource --- coverage/.last_run.json | 2 +- products/compute/api.yaml | 114 +++++++++ products/compute/examples/ansible/router.yaml | 47 ++++ .../compute/examples/chef/delete_router.rb | 39 ++++ products/compute/examples/chef/router.rb | 62 +++++ .../compute/examples/puppet/delete_router.pp | 37 +++ products/compute/examples/puppet/router.pp | 60 +++++ products/compute/terraform.yaml | 37 +++ provider/terraform/resource_override.rb | 4 + templates/terraform/resource.erb | 37 +++ .../tests/resource_compute_router_test.go | 216 ++++++++++++++++++ 11 files changed, 654 insertions(+), 1 deletion(-) create mode 100644 products/compute/examples/ansible/router.yaml create mode 100644 products/compute/examples/chef/delete_router.rb create mode 100644 products/compute/examples/chef/router.rb create mode 100644 products/compute/examples/puppet/delete_router.pp create mode 100644 products/compute/examples/puppet/router.pp create mode 100644 templates/terraform/tests/resource_compute_router_test.go diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 3c082d7b3c6b..32b57c5c4f2c 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 80.43 + "covered_percent": 80.04 } } diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 14232bcea510..c02804f12b1e 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -2565,6 +2565,120 @@ objects: output: true description: | URL to a Network that should handle matching packets. + - !ruby/object:Api::Resource + name: 'Router' + kind: 'compute#router' + base_url: projects/{{project}}/regions/{{region}}/routers + exports: + - !ruby/object:Api::Type::SelfLink + name: 'selfLink' + description: | + Represents a Router resource. + references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Google Cloud Router': 'https://cloud.google.com/router/docs/' + api: 'https://cloud.google.com/compute/docs/reference/rest/v1/routers' +<%= indent(compile_file({}, 'templates/regional_async.yaml.erb'), 4) %> + parameters: + - !ruby/object:Api::Type::ResourceRef + name: region + resource: Region + imports: name + description: Region where the router resides. + input: true + required: true + properties: + - !ruby/object:Api::Type::Integer + name: 'id' + description: 'The unique identifier for the resource.' + output: true + - !ruby/object:Api::Type::Time + name: 'creationTimestamp' + description: 'Creation timestamp in RFC3339 text format.' + output: true + - !ruby/object:Api::Type::String + name: name + description: | + Name of the resource. The name must be 1-63 characters long, and + comply with RFC1035. Specifically, the name must be 1-63 characters + long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` + which means the first character must be a lowercase letter, and all + following characters must be a dash, lowercase letter, or digit, + except the last character, which cannot be a dash. + input: true + required: true + - !ruby/object:Api::Type::String + name: description + description: | + An optional description of this resource. + - !ruby/object:Api::Type::ResourceRef + name: network + resource: Network + imports: 'selfLink' + description: | + A reference to the network to which this router belongs. + required: true + input: true + # TODO(danawillow): Figure out the story for interfaces/bgpPeers. Right + # now in Terraform we have three separate resources: router, + # router_interface, and router_peer. Decide whether we want to keep that + # pattern for the other providers, keep it unique for Terraform, or add + # these fields to the Terraform resource (and then within that, decide + # whether to deprecate router_interface and router_peer or leave them + # alone). + - !ruby/object:Api::Type::NestedObject + name: bgp + description: | + BGP information specific to this router. + properties: + - !ruby/object:Api::Type::Integer + name: asn + description: | + Local BGP Autonomous System Number (ASN). Must be an RFC6996 + private ASN, either 16-bit or 32-bit. The value will be fixed for + this router resource. All VPN tunnels that link to this router + will have the same local ASN. + required: true + - !ruby/object:Api::Type::Enum + name: advertiseMode + description: | + User-specified flag to indicate which mode to use for advertisement. + + Valid values of this enum field are: DEFAULT, CUSTOM + values: + - :DEFAULT + - :CUSTOM + default_value: :DEFAULT + - !ruby/object:Api::Type::Array + name: advertisedGroups + description: | + User-specified list of prefix groups to advertise in custom mode. + This field can only be populated if advertiseMode is CUSTOM and + is advertised to all peers of the router. These groups will be + advertised in addition to any specified prefixes. Leave this field + blank to advertise no custom groups. + + This enum field has the one valid value: ALL_SUBNETS + item_type: Api::Type::String # TODO(#324): enum? + - !ruby/object:Api::Type::Array + name: advertisedIpRanges + description: | + User-specified list of individual IP ranges to advertise in + custom mode. This field can only be populated if advertiseMode + is CUSTOM and is advertised to all peers of the router. These IP + ranges will be advertised in addition to any specified groups. + Leave this field blank to advertise no custom IP ranges. + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::String + name: range + description: | + The IP range to advertise. The value must be a + CIDR-formatted string. + - !ruby/object:Api::Type::String + name: description + description: | + User-specified description for the IP range. - !ruby/object:Api::Resource name: 'Snapshot' kind: 'compute#snapshot' diff --git a/products/compute/examples/ansible/router.yaml b/products/compute/examples/ansible/router.yaml new file mode 100644 index 000000000000..719b0df2cde0 --- /dev/null +++ b/products/compute/examples/ansible/router.yaml @@ -0,0 +1,47 @@ +# Copyright 2018 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. +--- !ruby/object:Provider::Ansible::Example +dependencies: + - !ruby/object:Provider::Ansible::Task + name: gcp_compute_network + register: network + code: | + name: <%= dependency_name('network', 'router') %> + project: <%= ctx[:project] %> + auth_kind: <%= ctx[:auth_kind] %> + service_account_file: <%= ctx[:service_account_file] %> +task: !ruby/object:Provider::Ansible::Task + name: gcp_compute_router + code: | + name: <%= ctx[:name] %> + network: "{{ network }}" + bgp: + asn: 64514 + advertise_mode: 'CUSTOM' + advertised_groups: + - 'ALL_SUBNETS' + advertised_ip_ranges: + - range: '1.2.3.4' + - range: '6.7.0.0/16' + project: <%= ctx[:project] %> + auth_kind: <%= ctx[:auth_kind] %> + service_account_file: <%= ctx[:service_account_file] %> +verifier: !ruby/object:Provider::Ansible::Verifier + command: | + gcloud compute routers describe + --project="{{ gcp_project}}" + --region=us-west1 + "{{ resource_name }}" + failure: !ruby/object:Provider::Ansible::ComputeFailureCondition + region: regions/us-west1 + type: routes diff --git a/products/compute/examples/chef/delete_router.rb b/products/compute/examples/chef/delete_router.rb new file mode 100644 index 000000000000..1af63a338dd7 --- /dev/null +++ b/products/compute/examples/chef/delete_router.rb @@ -0,0 +1,39 @@ +<% if false # the license inside this if block assertains to this file -%> +# Copyright 2018 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 -%> +<% if name != 'README.md' -%> + +<%= compile 'templates/license.erb' -%> + +<%= lines(autogen_notice :chef) -%> + +<%= compile 'templates/chef/example~auth.rb.erb' -%> + +gcompute_region <%= example_resource_name('some-region') -%> do + action :create + r_label 'us-west1' + project ENV['PROJECT'] # ex: 'my-test-project' + credential 'mycred' +end + +<% else # name == README.md -%> +# Router requires a network and a region, so define them in your recipe: +# - gcompute_region 'some-region' do ... end +<% end # name == README.md -%> +gcompute_router <%= example_resource_name('my-router') -%> do + action :delete + region <%= example_resource_name('some-region') %> + project ENV['PROJECT'] # ex: 'my-test-project' + credential 'mycred' +end diff --git a/products/compute/examples/chef/router.rb b/products/compute/examples/chef/router.rb new file mode 100644 index 000000000000..e141a7cabc0b --- /dev/null +++ b/products/compute/examples/chef/router.rb @@ -0,0 +1,62 @@ +<% if false # the license inside this if block assertains to this file -%> +# Copyright 2018 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 -%> +<% unless name == 'README.md' -%> + +<%= compile 'templates/license.erb' -%> + +<%= lines(autogen_notice :chef) -%> + +<%= compile 'templates/chef/example~auth.rb.erb' -%> + +<% end -%> +<% if name == "README.md" -%> +# Router requires a network and a region, so define them in your recipe: +# - gcompute_network 'my-network' do ... end +# - gcompute_region 'some-region' do ... end +<% else # name == README.md -%> +gcompute_network <%= example_resource_name('my-network') -%> do + action :create + project ENV['PROJECT'] # ex: 'my-test-project' + credential 'mycred' +end + +gcompute_region <%= example_resource_name('some-region') -%> do + action :create + r_label 'us-west1' + project ENV['PROJECT'] # ex: 'my-test-project' + credential 'mycred' +end + +<% end # name == README.md -%> +gcompute_router <%= example_resource_name('my-router') -%> do + action :create + bgp( + asn 64514 + advertise_mode 'CUSTOM' + advertised_groups ['ALL_SUBNETS'] + advertised_ip_ranges [ + { + range '1.2.3.4' + } + { + range '6.7.0.0/16' + } + ] + ) + network <%= example_resource_name('my-network') %> + region <%= example_resource_name('some-region') %> + project ENV['PROJECT'] # ex: 'my-test-project' + credential 'mycred' +end diff --git a/products/compute/examples/puppet/delete_router.pp b/products/compute/examples/puppet/delete_router.pp new file mode 100644 index 000000000000..9e89cbe6421d --- /dev/null +++ b/products/compute/examples/puppet/delete_router.pp @@ -0,0 +1,37 @@ +<% if false # the license inside this if block assertains to this file -%> +# Copyright 2018 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 -%> +<% if name != "README.md" -%> +<%= compile 'templates/license.erb' -%> + +<%= lines(autogen_notice :puppet) -%> + +<%= compile 'templates/puppet/examples~credential.pp.erb' -%> + +gcompute_region { <%= example_resource_name('some-region') -%>: + name => 'us-west1', + project => $project, # e.g. 'my-test-project' + credential => 'mycred', +} + +<% else # name == README.md -%> +# Router requires a network and a region, so define them in your manifest: +# - gcompute_region { 'some-region': ... } +<% end # name == README.md -%> +gcompute_router { <%= example_resource_name('my-router') -%>: + ensure => absent, + region => <%= example_resource_name('some-region') -%>, + project => $project, # e.g. 'my-test-project' + credential => 'mycred', +} diff --git a/products/compute/examples/puppet/router.pp b/products/compute/examples/puppet/router.pp new file mode 100644 index 000000000000..3b8b6ea73991 --- /dev/null +++ b/products/compute/examples/puppet/router.pp @@ -0,0 +1,60 @@ +<% if false # the license inside this if block assertains to this file -%> +# Copyright 2018 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 -%> +<% unless name == "README.md" -%> +<%= compile 'templates/license.erb' -%> + +<%= lines(autogen_notice :puppet) -%> + +<%= compile 'templates/puppet/examples~credential.pp.erb' -%> + +<% end # name == README.md -%> +<% if name == "README.md" -%> +# Router requires a network and a region, so define them in your manifest: +# - gcompute_network { 'my-network': ensure => present } +# - gcompute_region { 'some-region': ... } +<% else # name == README.md -%> +gcompute_network { <%= example_resource_name('my-network') -%>: + ensure => present, + project => $project, # e.g. 'my-test-project' + credential => 'mycred', +} + +gcompute_region { <%= example_resource_name('some-region') -%>: + name => 'us-west1', + project => $project, # e.g. 'my-test-project' + credential => 'mycred', +} + +<% end # name == README.md -%> +gcompute_router { <%= example_resource_name('my-router') -%>: + ensure => present, + network => <%= example_resource_name('my-network') -%>, + bgp => { + asn => 64514, + advertise_mode => 'CUSTOM', + advertised_groups => ['ALL_SUBNETS'], + advertised_ip_ranges => [ + { + range => '1.2.3.4', + }, + { + range => '6.7.0.0/16', + } + ] + }, + region => <%= example_resource_name('some-region') -%>, + project => $project, # e.g. 'my-test-project' + credential => 'mycred', +} diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index 4c0a4194ae41..8a04832a43f3 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -540,7 +540,42 @@ overrides: !ruby/object:Provider::ResourceOverrides specified) The zone of the instance specified in `next_hop_instance`. Omit if `next_hop_instance` is specified as a URL. + Router: !ruby/object:Provider::Terraform::ResourceOverride + id_format: "{{region}}/{{name}}" + mutex: router/{{region}}/{{name}} + examples: | + ```hcl + resource "google_compute_network" "foobar" { + name = "my-network" + auto_create_subnetworks = false + } + resource "google_compute_router" "foobar" { + name = "my-router" + network = "${google_compute_network.foobar.name}" + bgp { + asn = 64514 + advertise_mode = "CUSTOM" + advertised_groups = ["ALL_SUBNETS"] + advertised_ip_ranges { + range = "1.2.3.4" + } + advertised_ip_ranges { + range = "6.7.0.0/16" + } + } + } + ``` + properties: + id: !ruby/object:Provider::Terraform::PropertyOverride + exclude: true + name: !ruby/object:Provider::Terraform::PropertyOverride + validation: !ruby/object:Provider::Terraform::Validation + function: 'validateGCPName' + region: !ruby/object:Provider::Terraform::PropertyOverride + required: false + default_from_api: true + custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb' Snapshot: !ruby/object:Provider::Terraform::ResourceOverride exclude: true SslCertificate: !ruby/object:Provider::Terraform::ResourceOverride @@ -982,6 +1017,8 @@ files: !ruby/object:Provider::Config::Files 'templates/terraform/tests/resource_compute_global_address_test.go' 'google/resource_compute_region_autoscaler_test.go': 'templates/terraform/tests/resource_compute_region_autoscaler_test.go' + 'google/resource_compute_router_test.go': + 'templates/terraform/tests/resource_compute_router_test.go' 'google/resource_compute_target_https_proxy_test.go': 'templates/terraform/tests/resource_compute_target_https_proxy_test.go' 'google/resource_compute_target_ssl_proxy_test.go': diff --git a/provider/terraform/resource_override.rb b/provider/terraform/resource_override.rb index 16dc54591e10..b4893598dcd1 100644 --- a/provider/terraform/resource_override.rb +++ b/provider/terraform/resource_override.rb @@ -27,6 +27,10 @@ module OverrideProperties attr_reader :custom_code attr_reader :docs + # Lock name for a mutex to prevent concurrent API calls for a given + # resource. + attr_reader :mutex + attr_reader :examples end diff --git a/templates/terraform/resource.erb b/templates/terraform/resource.erb index ef34c2bc1623..1e06c5747c3e 100644 --- a/templates/terraform/resource.erb +++ b/templates/terraform/resource.erb @@ -106,6 +106,15 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ } <% end -%> +<% if object.mutex -%> + lockName, err := replaceVars(d, config, "<%= object.mutex -%>") + if err != nil { + return err + } + mutexKV.Lock(lockName) + defer mutexKV.Unlock(lockName) +<% end -%> + url, err := replaceVars(d, config, "<%= collection_url(object) -%>") if err != nil { return err @@ -269,6 +278,15 @@ func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{ <% end -%> <% end -%> +<% if object.mutex -%> + lockName, err := replaceVars(d, config, "<%= object.mutex -%>") + if err != nil { + return err + } + mutexKV.Lock(lockName) + defer mutexKV.Unlock(lockName) +<% end -%> + url, err = replaceVars(d, config, "<%= update_url(object, key[:update_url]) -%>") if err != nil { return err @@ -322,6 +340,16 @@ func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{ <% elsif object.custom_code.encoder -%> obj, err = resource<%= resource_name -%>Encoder(d, meta, obj) <% end -%> + +<% if object.mutex -%> + lockName, err := replaceVars(d, config, "<%= object.mutex -%>") + if err != nil { + return err + } + mutexKV.Lock(lockName) + defer mutexKV.Unlock(lockName) +<% end -%> + url, err := replaceVars(d, config, "<%= update_url(object, object.update_url) -%>") if err != nil { return err @@ -367,6 +395,15 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{ } <% end -%> +<% if object.mutex -%> + lockName, err := replaceVars(d, config, "<%= object.mutex -%>") + if err != nil { + return err + } + mutexKV.Lock(lockName) + defer mutexKV.Unlock(lockName) +<% end -%> + url, err := replaceVars(d, config, "<%= self_link_url(object) -%>") if err != nil { return err diff --git a/templates/terraform/tests/resource_compute_router_test.go b/templates/terraform/tests/resource_compute_router_test.go new file mode 100644 index 000000000000..336f5447ef80 --- /dev/null +++ b/templates/terraform/tests/resource_compute_router_test.go @@ -0,0 +1,216 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccComputeRouter_basic(t *testing.T) { + t.Parallel() + + testId := acctest.RandString(10) + resourceRegion := "europe-west1" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRouterDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeRouterBasic(testId, resourceRegion), + }, + resource.TestStep{ + ResourceName: "google_compute_router.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRouter_noRegion(t *testing.T) { + t.Parallel() + + testId := acctest.RandString(10) + providerRegion := "us-central1" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRouterDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeRouterNoRegion(testId, providerRegion), + }, + resource.TestStep{ + ResourceName: "google_compute_router.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRouter_full(t *testing.T) { + t.Parallel() + + testId := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRouterDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeRouterFull(testId), + }, + resource.TestStep{ + ResourceName: "google_compute_router.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccComputeRouter_update(t *testing.T) { + t.Parallel() + + testId := acctest.RandString(10) + region := getTestRegionFromEnv() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRouterDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeRouterBasic(testId, region), + }, + resource.TestStep{ + ResourceName: "google_compute_router.foobar", + ImportState: true, + ImportStateVerify: true, + }, + resource.TestStep{ + Config: testAccComputeRouterFull(testId), + }, + resource.TestStep{ + ResourceName: "google_compute_router.foobar", + ImportState: true, + ImportStateVerify: true, + }, + resource.TestStep{ + Config: testAccComputeRouterBasic(testId, region), + }, + resource.TestStep{ + ResourceName: "google_compute_router.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckComputeRouterDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + + routersService := config.clientCompute.Routers + + for _, rs := range s.RootModule().Resources { + if rs.Type != "google_compute_router" { + continue + } + + project, err := getTestProject(rs.Primary, config) + if err != nil { + return err + } + + region, err := getTestRegion(rs.Primary, config) + if err != nil { + return err + } + + name := rs.Primary.Attributes["name"] + + _, err = routersService.Get(project, region, name).Do() + + if err == nil { + return fmt.Errorf("Error, Router %s in region %s still exists", + name, region) + } + } + + return nil +} + +func testAccComputeRouterBasic(testId, resourceRegion string) string { + return fmt.Sprintf(` + resource "google_compute_network" "foobar" { + name = "router-test-%s" + auto_create_subnetworks = false + } + resource "google_compute_subnetwork" "foobar" { + name = "router-test-subnetwork-%s" + network = "${google_compute_network.foobar.self_link}" + ip_cidr_range = "10.0.0.0/16" + region = "%s" + } + resource "google_compute_router" "foobar" { + name = "router-test-%s" + region = "${google_compute_subnetwork.foobar.region}" + network = "${google_compute_network.foobar.name}" + bgp { + asn = 64514 + } + } + `, testId, testId, resourceRegion, testId) +} + +func testAccComputeRouterNoRegion(testId, providerRegion string) string { + return fmt.Sprintf(` + resource "google_compute_network" "foobar" { + name = "router-test-%s" + auto_create_subnetworks = false + } + resource "google_compute_subnetwork" "foobar" { + name = "router-test-subnetwork-%s" + network = "${google_compute_network.foobar.self_link}" + ip_cidr_range = "10.0.0.0/16" + region = "%s" + } + resource "google_compute_router" "foobar" { + name = "router-test-%s" + network = "${google_compute_network.foobar.name}" + bgp { + asn = 64514 + } + } + `, testId, testId, providerRegion, testId) +} + +func testAccComputeRouterFull(testId string) string { + return fmt.Sprintf(` + resource "google_compute_network" "foobar" { + name = "router-test-%s" + auto_create_subnetworks = false + } + + resource "google_compute_router" "foobar" { + name = "router-test-%s" + network = "${google_compute_network.foobar.name}" + bgp { + asn = 64514 + advertise_mode = "CUSTOM" + advertised_groups = ["ALL_SUBNETS"] + advertised_ip_ranges { + range = "1.2.3.4" + } + advertised_ip_ranges { + range = "6.7.0.0/16" + } + } + } + `, testId, testId) +}