From 0a806e7115cd78bd2c6adfe6143f3329a4d95f63 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 19 Dec 2019 13:08:18 -0800 Subject: [PATCH] use atleastoneof for router interface fields (#5225) Signed-off-by: Modular Magician --- google/resource_compute_router_interface.go | 28 ++++--------------- google/resource_sql_database_instance_test.go | 1 + 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/google/resource_compute_router_interface.go b/google/resource_compute_router_interface.go index d7c82cc8bc2..5b2ed866d1e 100644 --- a/google/resource_compute_router_interface.go +++ b/google/resource_compute_router_interface.go @@ -20,8 +20,6 @@ func resourceComputeRouterInterface() *schema.Resource { State: resourceComputeRouterInterfaceImportState, }, - CustomizeDiff: routerInterfaceDiffOneOfCheck, - Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -39,6 +37,7 @@ func resourceComputeRouterInterface() *schema.Resource { Optional: true, ForceNew: true, DiffSuppressFunc: compareSelfLinkOrResourceName, + AtLeastOneOf: []string{"vpn_tunnel", "interconnect_attachment", "ip_range"}, }, "interconnect_attachment": { Type: schema.TypeString, @@ -46,11 +45,13 @@ func resourceComputeRouterInterface() *schema.Resource { Optional: true, ForceNew: true, DiffSuppressFunc: compareSelfLinkOrResourceName, + AtLeastOneOf: []string{"vpn_tunnel", "interconnect_attachment", "ip_range"}, }, "ip_range": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + AtLeastOneOf: []string{"vpn_tunnel", "interconnect_attachment", "ip_range"}, }, "project": { Type: schema.TypeString, @@ -291,20 +292,3 @@ func resourceComputeRouterInterfaceImportState(d *schema.ResourceData, meta inte return []*schema.ResourceData{d}, nil } - -func routerInterfaceDiffOneOfCheck(d *schema.ResourceDiff, meta interface{}) error { - _, ipOk := d.GetOk("ip_range") - _, vpnOk := d.GetOk("vpn_tunnel") - _, icOk := d.GetOk("interconnect_attachment") - // When unset, these values are all known. However, if the value is an - // interpolation to a resource that hasn't been created, the value is - // unknown and d.GetOk will return false. For each value, if that value is - // unknown, consider it true-ish. - if !((ipOk || !d.NewValueKnown("ip_range")) || - (vpnOk || !d.NewValueKnown("vpn_tunnel")) || - (icOk || !d.NewValueKnown("interconnect_attachment"))) { - return fmt.Errorf("Each interface requires one linked resource or an ip range, or both.") - } - - return nil -} diff --git a/google/resource_sql_database_instance_test.go b/google/resource_sql_database_instance_test.go index 11c939db0d2..069037b74f2 100644 --- a/google/resource_sql_database_instance_test.go +++ b/google/resource_sql_database_instance_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + sqladmin "google.golang.org/api/sqladmin/v1beta4" )