Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions bastion/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
)

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) {
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) {
client := ec2.New(sess)

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



blockDeviceMapping := &ec2.BlockDeviceMapping{
DeviceName: aws.String("/dev/xvda"), // Using default mapping
Ebs: &ec2.EbsBlockDevice{
VolumeSize: aws.Int64(8), // Default size GiB;
VolumeSize: aws.Int64(volumeSize),
VolumeType: aws.String(volumeType),
Encrypted: aws.Bool(volumeEncryption),
DeleteOnTermination: aws.Bool(true), // Default behavior
DeleteOnTermination: aws.Bool(true), // Default behavior
},
}

input.BlockDeviceMappings = []*ec2.BlockDeviceMapping{
blockDeviceMapping,
}



if public {
input.NetworkInterfaces = []*ec2.InstanceNetworkInterfaceSpecification{
Expand Down
21 changes: 16 additions & 5 deletions bastion/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func CreateBastion(c *cli.Context) (string, string, error) {
spot bool
publicIpAddress bool
bastionInstanceId string
volumeSize int64
volumeEncryption bool
volumeType string
)
Expand Down Expand Up @@ -126,16 +127,21 @@ func CreateBastion(c *cli.Context) (string, string, error) {
publicIpAddress = false
}

volumeSize = 8
if c.IsSet("volume-size") {
volumeSize = c.Int64("volume-size") //Default volume-size
}

volumeEncryption = true
if c.Bool("volume-encryption") {
volumeEncryption = false
}
volumeType = c.String("volume-type")

volumeType = c.String("volume-type")
if volumeType == "" {
volumeType = "gp2" //Default volume-type
}

subnetId = c.String("subnet-id")
if subnetId == "" {
subnets, err := GetSubnets(sess)
Expand Down Expand Up @@ -165,7 +171,7 @@ func CreateBastion(c *cli.Context) (string, string, error) {

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

bastionInstanceId, err = StartEc2(id, sess, ami, instanceProfile, subnetId, securitygroupId, instanceType, launchedBy, userdata, keyName, spot, publicIpAddress, volumeEncryption, volumeType)
bastionInstanceId, err = StartEc2(id, sess, ami, instanceProfile, subnetId, securitygroupId, instanceType, launchedBy, userdata, keyName, spot, publicIpAddress, volumeSize, volumeEncryption, volumeType)
if err != nil {
return "", "", err
}
Expand All @@ -190,6 +196,7 @@ func CmdLaunchWindowsBastion(c *cli.Context) error {
spot bool
publicIpAddress bool
bastionInstanceId string
volumeSize int64
volumeEncryption bool
volumeType string
)
Expand Down Expand Up @@ -224,13 +231,17 @@ func CmdLaunchWindowsBastion(c *cli.Context) error {
publicIpAddress = false
}

volumeSize = 8
if c.IsSet("volume-size") {
volumeSize = c.Int64("volume-size") //Default volume-size
}

volumeEncryption = true
if c.Bool("volume-encryption") {
volumeEncryption = false
}

volumeType = c.String("volume-type")

if volumeType == "" {
volumeType = "gp2" //Default volume-type
}
Expand Down Expand Up @@ -281,7 +292,7 @@ func CmdLaunchWindowsBastion(c *cli.Context) error {

userdata = BuildWindowsUserdata()

bastionInstanceId, err = StartEc2(id, sess, ami, instanceProfile, subnetId, securitygroupId, instanceType, launchedBy, userdata, keyName, spot, publicIpAddress, volumeEncryption, volumeType)
bastionInstanceId, err = StartEc2(id, sess, ami, instanceProfile, subnetId, securitygroupId, instanceType, launchedBy, userdata, keyName, spot, publicIpAddress, volumeSize, volumeEncryption, volumeType)
if err != nil {
return err
}
Expand Down
14 changes: 12 additions & 2 deletions entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,18 @@ func CliMain() {
Aliases: []string{"o"},
Usage: "any additional ssh options such as tunnels '-L 3306:db.internal.example.com:3306'",
},
&cli.Int64Flag{
Name: "volume-size",
Value: 8,
Usage: "specify volume size in GB",
},
&cli.BoolFlag{
Name: "volume-encryption",
Usage: "enable volume encryption",
},
&cli.StringFlag{
Name: "volume-type",
Usage: "specify volume volume type [gp2, gp3, io2, io1]",
Usage: "specify volume type [gp2, gp3, io2, io1]",
},
},
},
Expand Down Expand Up @@ -173,13 +178,18 @@ func CliMain() {
Name: "private",
Usage: "don't attach a public IP to the bastion",
},
&cli.Int64Flag{
Name: "volume-size",
Value: 8,
Usage: "specify volume size in GB",
},
&cli.BoolFlag{
Name: "volume-encryption",
Usage: "enable volume encryption",
},
&cli.StringFlag{
Name: "volume-type",
Usage: "specify volume volume type [gp2, gp3, io2, io1]",
Usage: "specify volume type [gp2, gp3, io2, io1]",
},
},
},
Expand Down