Skip to content

Commit

Permalink
use atleastoneof for router interface fields (#5225)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and danawillow committed Dec 19, 2019
1 parent 6277960 commit 0a806e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
28 changes: 6 additions & 22 deletions google/resource_compute_router_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func resourceComputeRouterInterface() *schema.Resource {
State: resourceComputeRouterInterfaceImportState,
},

CustomizeDiff: routerInterfaceDiffOneOfCheck,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand All @@ -39,18 +37,21 @@ func resourceComputeRouterInterface() *schema.Resource {
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
AtLeastOneOf: []string{"vpn_tunnel", "interconnect_attachment", "ip_range"},
},
"interconnect_attachment": {
Type: schema.TypeString,
ConflictsWith: []string{"vpn_tunnel"},
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,
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit 0a806e7

Please sign in to comment.