Skip to content

Commit

Permalink
Merge pull request #1 from MicroMetrics/fix_crash_with_empty_ssh_key_id
Browse files Browse the repository at this point in the history
Fixes SSH key usage when creating droplets
  • Loading branch information
davefp authored Jun 28, 2021
2 parents a021b8c + 6e22602 commit d216b51
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions builder/digitalocean/step_create_droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ func (s *stepCreateDroplet) Run(ctx context.Context, state multistep.StateBag) m
client := state.Get("client").(*godo.Client)
ui := state.Get("ui").(packersdk.Ui)
c := state.Get("config").(*Config)
sshKeyId := state.Get("ssh_key_id").(int)
sshKeyId, hasSshKey := state.GetOk("ssh_key_id")

sshKeys := []godo.DropletCreateSSHKey{}

if hasSshKey {
sshKeys = append(sshKeys, godo.DropletCreateSSHKey{
ID: sshKeyId.(int),
})
}

// Create the droplet based on configuration
ui.Say("Creating droplet...")
Expand All @@ -40,13 +48,11 @@ func (s *stepCreateDroplet) Run(ctx context.Context, state multistep.StateBag) m
createImage := getImageType(c.Image)

dropletCreateReq := &godo.DropletCreateRequest{
Name: c.DropletName,
Region: c.Region,
Size: c.Size,
Image: createImage,
SSHKeys: []godo.DropletCreateSSHKey{
{ID: sshKeyId},
},
Name: c.DropletName,
Region: c.Region,
Size: c.Size,
Image: createImage,
SSHKeys: sshKeys,
PrivateNetworking: c.PrivateNetworking,
Monitoring: c.Monitoring,
IPv6: c.IPv6,
Expand Down

0 comments on commit d216b51

Please sign in to comment.