Skip to content

Commit 5a85a36

Browse files
authored
Merge pull request #30 from cfln123/main
Custom volume size
2 parents b770d86 + 8e0c43d commit 5a85a36

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

bastion/ec2.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/aws/aws-sdk-go/service/ec2"
1212
)
1313

14-
func StartEc2(id string, sess *session.Session, ami string, instanceProfile string, subnetId string, securitygroupId string, instanceType string, launchedBy string, userdata string, keyName string, spot bool, public bool, volumeEncryption bool, volumeType string) (string, error) {
14+
func StartEc2(id string, sess *session.Session, ami string, instanceProfile string, subnetId string, securitygroupId string, instanceType string, launchedBy string, userdata string, keyName string, spot bool, public bool, volumeSize int64, volumeEncryption bool, volumeType string) (string, error) {
1515
client := ec2.New(sess)
1616

1717
input := &ec2.RunInstancesInput{
@@ -45,23 +45,19 @@ func StartEc2(id string, sess *session.Session, ami string, instanceProfile stri
4545
},
4646
}
4747

48-
49-
5048
blockDeviceMapping := &ec2.BlockDeviceMapping{
5149
DeviceName: aws.String("/dev/xvda"), // Using default mapping
5250
Ebs: &ec2.EbsBlockDevice{
53-
VolumeSize: aws.Int64(8), // Default size GiB;
51+
VolumeSize: aws.Int64(volumeSize),
5452
VolumeType: aws.String(volumeType),
5553
Encrypted: aws.Bool(volumeEncryption),
56-
DeleteOnTermination: aws.Bool(true), // Default behavior
54+
DeleteOnTermination: aws.Bool(true), // Default behavior
5755
},
5856
}
5957

6058
input.BlockDeviceMappings = []*ec2.BlockDeviceMapping{
6159
blockDeviceMapping,
6260
}
63-
64-
6561

6662
if public {
6763
input.NetworkInterfaces = []*ec2.InstanceNetworkInterfaceSpecification{

bastion/launch.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func CreateBastion(c *cli.Context) (string, string, error) {
7676
spot bool
7777
publicIpAddress bool
7878
bastionInstanceId string
79+
volumeSize int64
7980
volumeEncryption bool
8081
volumeType string
8182
)
@@ -126,16 +127,21 @@ func CreateBastion(c *cli.Context) (string, string, error) {
126127
publicIpAddress = false
127128
}
128129

130+
volumeSize = 8
131+
if c.IsSet("volume-size") {
132+
volumeSize = c.Int64("volume-size") //Default volume-size
133+
}
134+
129135
volumeEncryption = true
130136
if c.Bool("volume-encryption") {
131137
volumeEncryption = false
132138
}
133-
volumeType = c.String("volume-type")
134139

140+
volumeType = c.String("volume-type")
135141
if volumeType == "" {
136142
volumeType = "gp2" //Default volume-type
137143
}
138-
144+
139145
subnetId = c.String("subnet-id")
140146
if subnetId == "" {
141147
subnets, err := GetSubnets(sess)
@@ -165,7 +171,7 @@ func CreateBastion(c *cli.Context) (string, string, error) {
165171

166172
userdata = BuildLinuxUserdata(sshKey, c.String("ssh-user"), expire, expireAfter, c.String("efs"), c.String("access-points"))
167173

168-
bastionInstanceId, err = StartEc2(id, sess, ami, instanceProfile, subnetId, securitygroupId, instanceType, launchedBy, userdata, keyName, spot, publicIpAddress, volumeEncryption, volumeType)
174+
bastionInstanceId, err = StartEc2(id, sess, ami, instanceProfile, subnetId, securitygroupId, instanceType, launchedBy, userdata, keyName, spot, publicIpAddress, volumeSize, volumeEncryption, volumeType)
169175
if err != nil {
170176
return "", "", err
171177
}
@@ -190,6 +196,7 @@ func CmdLaunchWindowsBastion(c *cli.Context) error {
190196
spot bool
191197
publicIpAddress bool
192198
bastionInstanceId string
199+
volumeSize int64
193200
volumeEncryption bool
194201
volumeType string
195202
)
@@ -224,13 +231,17 @@ func CmdLaunchWindowsBastion(c *cli.Context) error {
224231
publicIpAddress = false
225232
}
226233

234+
volumeSize = 8
235+
if c.IsSet("volume-size") {
236+
volumeSize = c.Int64("volume-size") //Default volume-size
237+
}
238+
227239
volumeEncryption = true
228240
if c.Bool("volume-encryption") {
229241
volumeEncryption = false
230242
}
231243

232244
volumeType = c.String("volume-type")
233-
234245
if volumeType == "" {
235246
volumeType = "gp2" //Default volume-type
236247
}
@@ -281,7 +292,7 @@ func CmdLaunchWindowsBastion(c *cli.Context) error {
281292

282293
userdata = BuildWindowsUserdata()
283294

284-
bastionInstanceId, err = StartEc2(id, sess, ami, instanceProfile, subnetId, securitygroupId, instanceType, launchedBy, userdata, keyName, spot, publicIpAddress, volumeEncryption, volumeType)
295+
bastionInstanceId, err = StartEc2(id, sess, ami, instanceProfile, subnetId, securitygroupId, instanceType, launchedBy, userdata, keyName, spot, publicIpAddress, volumeSize, volumeEncryption, volumeType)
285296
if err != nil {
286297
return err
287298
}

entrypoint/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,18 @@ func CliMain() {
105105
Aliases: []string{"o"},
106106
Usage: "any additional ssh options such as tunnels '-L 3306:db.internal.example.com:3306'",
107107
},
108+
&cli.Int64Flag{
109+
Name: "volume-size",
110+
Value: 8,
111+
Usage: "specify volume size in GB",
112+
},
108113
&cli.BoolFlag{
109114
Name: "volume-encryption",
110115
Usage: "enable volume encryption",
111116
},
112117
&cli.StringFlag{
113118
Name: "volume-type",
114-
Usage: "specify volume volume type [gp2, gp3, io2, io1]",
119+
Usage: "specify volume type [gp2, gp3, io2, io1]",
115120
},
116121
},
117122
},
@@ -173,13 +178,18 @@ func CliMain() {
173178
Name: "private",
174179
Usage: "don't attach a public IP to the bastion",
175180
},
181+
&cli.Int64Flag{
182+
Name: "volume-size",
183+
Value: 8,
184+
Usage: "specify volume size in GB",
185+
},
176186
&cli.BoolFlag{
177187
Name: "volume-encryption",
178188
Usage: "enable volume encryption",
179189
},
180190
&cli.StringFlag{
181191
Name: "volume-type",
182-
Usage: "specify volume volume type [gp2, gp3, io2, io1]",
192+
Usage: "specify volume type [gp2, gp3, io2, io1]",
183193
},
184194
},
185195
},

0 commit comments

Comments
 (0)