Skip to content

Commit

Permalink
use atleastoneof for router interface fields (#2852)
Browse files Browse the repository at this point in the history
Merged PR #2852.
  • Loading branch information
danawillow authored and modular-magician committed Dec 19, 2019
1 parent 519b33c commit f374eb7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build/inspec
Submodule inspec updated 1 files
+2 −1 .rubocop.yml
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
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
}

0 comments on commit f374eb7

Please sign in to comment.