Skip to content

Commit

Permalink
Get a random subnet id from a list of subnet ids (#9056)
Browse files Browse the repository at this point in the history
Co-authored-by: Pankti Shah <shah.pankti2609@gmail.com>
  • Loading branch information
eks-distro-pr-bot and panktishah26 authored Dec 7, 2024
1 parent 913fcae commit 2bde854
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 2bde854

Please sign in to comment.