Skip to content

Commit

Permalink
fix(lb): early validation for lb_target arguments (#721)
Browse files Browse the repository at this point in the history
The current validation is only executed on `apply`. By utilizing the
schema to do the validation it will already execute in the `plan` stage.
  • Loading branch information
apricote committed Jul 13, 2023
1 parent aad0614 commit 10928d1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions internal/loadbalancer/resource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ func NetworkResource() *schema.Resource {
},
Schema: map[string]*schema.Schema{
"network_id": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Type: schema.TypeInt,
ExactlyOneOf: []string{"network_id", "subnet_id"},
Optional: true,
ForceNew: true,
},
"subnet_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
ExactlyOneOf: []string{"network_id", "subnet_id"},
Optional: true,
ForceNew: true,
},
"load_balancer_id": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -71,11 +73,8 @@ func resourceLoadBalancerNetworkCreate(ctx context.Context, d *schema.ResourceDa

ip := net.ParseIP(d.Get("ip").(string))

networkID, nwIDSet := d.GetOk("network_id")
networkID, _ := d.GetOk("network_id")
subNetID, snIDSet := d.GetOk("subnet_id")
if (nwIDSet && snIDSet) || (!nwIDSet && !snIDSet) {
return diag.Errorf("either network_id or subnet_id must be set")
}

if snIDSet {
nwID, _, err := network.ParseSubnetID(subNetID.(string))
Expand Down

0 comments on commit 10928d1

Please sign in to comment.