Skip to content

Commit

Permalink
Fixes SSH key usage when creating droplets
Browse files Browse the repository at this point in the history
  • Loading branch information
davefp committed Jun 28, 2021
1 parent a021b8c commit 6e22602
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 6e22602

Please sign in to comment.