Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit a639dc8

Browse files
committed
Add ssh-port flag to the amazonec2 driver
Also changes the description of the amazonec2-ssh-user flag to be more consistent with other drivers. Signed-off-by: Timothy Jones <tim@zmthy.net>
1 parent 49dfaa7 commit a639dc8

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

drivers/amazonec2/amazonec2.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
defaultVolumeType = "gp2"
4040
defaultZone = "a"
4141
defaultSecurityGroup = machineSecurityGroupName
42+
defaultSSHPort = 22
4243
defaultSSHUser = "ubuntu"
4344
defaultSpotPrice = "0.50"
4445
defaultBlockDurationMinutes = 0
@@ -203,9 +204,15 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
203204
Usage: "AWS IAM Instance Profile",
204205
EnvVar: "AWS_INSTANCE_PROFILE",
205206
},
207+
mcnflag.IntFlag{
208+
Name: "amazonec2-ssh-port",
209+
Usage: "SSH port",
210+
Value: defaultSSHPort,
211+
EnvVar: "AWS_SSH_PORT",
212+
},
206213
mcnflag.StringFlag{
207214
Name: "amazonec2-ssh-user",
208-
Usage: "Set the name of the ssh user",
215+
Usage: "SSH username",
209216
Value: defaultSSHUser,
210217
EnvVar: "AWS_SSH_USER",
211218
},
@@ -286,6 +293,7 @@ func NewDriver(hostName, storePath string) *Driver {
286293
SpotPrice: defaultSpotPrice,
287294
BlockDurationMinutes: defaultBlockDurationMinutes,
288295
BaseDriver: &drivers.BaseDriver{
296+
SSHPort: defaultSSHPort,
289297
SSHUser: defaultSSHUser,
290298
MachineName: hostName,
291299
StorePath: storePath,
@@ -354,7 +362,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
354362
d.VolumeType = flags.String("amazonec2-volume-type")
355363
d.IamInstanceProfile = flags.String("amazonec2-iam-instance-profile")
356364
d.SSHUser = flags.String("amazonec2-ssh-user")
357-
d.SSHPort = 22
365+
d.SSHPort = flags.Int("amazonec2-ssh-port")
358366
d.PrivateIPOnly = flags.Bool("amazonec2-private-address-only")
359367
d.UsePrivateIP = flags.Bool("amazonec2-use-private-address")
360368
d.Monitoring = flags.Bool("amazonec2-monitoring")
@@ -817,6 +825,14 @@ func (d *Driver) GetSSHHostname() (string, error) {
817825
return d.GetIP()
818826
}
819827

828+
func (d *Driver) GetSSHPort() (int, error) {
829+
if d.SSHPort == 0 {
830+
d.SSHPort = defaultSSHPort
831+
}
832+
833+
return d.SSHPort, nil
834+
}
835+
820836
func (d *Driver) GetSSHUsername() string {
821837
if d.SSHUser == "" {
822838
d.SSHUser = defaultSSHUser
@@ -1119,11 +1135,11 @@ func (d *Driver) configureSecurityGroupPermissions(group *ec2.SecurityGroup) ([]
11191135

11201136
perms := []*ec2.IpPermission{}
11211137

1122-
if !hasPorts["22/tcp"] {
1138+
if !hasPorts[fmt.Sprintf("%d/tcp", d.BaseDriver.SSHPort)] {
11231139
perms = append(perms, &ec2.IpPermission{
11241140
IpProtocol: aws.String("tcp"),
1125-
FromPort: aws.Int64(22),
1126-
ToPort: aws.Int64(22),
1141+
FromPort: aws.Int64(int64(d.BaseDriver.SSHPort)),
1142+
ToPort: aws.Int64(int64(d.BaseDriver.SSHPort)),
11271143
IpRanges: []*ec2.IpRange{{CidrIp: aws.String(ipRange)}},
11281144
})
11291145
}

0 commit comments

Comments
 (0)