Skip to content

Commit 2bde854

Browse files
Get a random subnet id from a list of subnet ids (#9056)
Co-authored-by: Pankti Shah <[email protected]>
1 parent 913fcae commit 2bde854

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/pkg/ec2/create.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/base64"
55
"fmt"
66
"math/rand"
7+
"strings"
78
"time"
89

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

112113
return false
113114
}
115+
116+
func getRandomSubnetID(subnetIDsStr string) string {
117+
subnetIDs := strings.Split(subnetIDsStr, ",")
118+
return subnetIDs[rand.Intn(len(subnetIDs))]
119+
}

0 commit comments

Comments
 (0)