Skip to content

Commit

Permalink
Get a random subnet id from a list of subnet ids
Browse files Browse the repository at this point in the history
  • Loading branch information
panktishah26 authored and eks-distro-pr-bot committed Dec 7, 2024
1 parent ff41392 commit 8ea8559
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/pkg/ec2/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"fmt"
"math/rand"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -61,7 +62,7 @@ func CreateInstance(session *session.Session, amiId, key, tag, instanceProfileNa
IamInstanceProfile: &ec2.IamInstanceProfileSpecification{
Name: aws.String(instanceProfileName),
},
SubnetId: aws.String(subnetId),
SubnetId: aws.String(getRandomSubnetID(subnetId)),
TagSpecifications: []*ec2.TagSpecification{
{
ResourceType: aws.String("instance"),
Expand Down Expand Up @@ -111,3 +112,8 @@ func isThrottleError(err error) bool {

return false
}

func getRandomSubnetID(subnetIDsStr string) string {
subnetIDs := strings.Split(subnetIDsStr, ",")
return subnetIDs[rand.Intn(len(subnetIDs))]
}

0 comments on commit 8ea8559

Please sign in to comment.