Skip to content

Commit

Permalink
Assign random IP from list during creation of glesys_ip
Browse files Browse the repository at this point in the history
  • Loading branch information
norrland committed Mar 8, 2024
1 parent ca4659f commit 2ad1e46
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions glesys/resource_glesys_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package glesys

import (
"context"
"math/rand"
"strings"
"time"

"github.com/glesys/glesys-go/v8"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -141,8 +143,10 @@ func resourceGlesysIPCreate(ctx context.Context, d *schema.ResourceData, m inter
return diag.Errorf("Error listing available IPs: %v", err)
}

// Select the first available ip address for reservation
address = (*ips)[0].Address
// Select a random available ip address for reservation
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))

address = (*ips)[r.Intn(len(*ips))].Address
}

ip, err := client.IPs.Reserve(ctx, address)
Expand Down

0 comments on commit 2ad1e46

Please sign in to comment.