Skip to content

Commit

Permalink
if ssh_key_id is specified skip generating temp ssh key
Browse files Browse the repository at this point in the history
  • Loading branch information
pragnesh committed Dec 9, 2023
1 parent 7c1135a commit 82bd5c8
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions builder/digitalocean/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,24 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
state.Put("hook", hook)
state.Put("ui", ui)

// Only generate the temp key pair if one is not already provided
genTempKeyPair := b.config.SSHKeyID == 0 || b.config.Comm.SSHPrivateKeyFile == ""

// Build the steps
steps := []multistep.Step{
&communicator.StepSSHKeyGen{
CommConf: &b.config.Comm,
SSHTemporaryKeyPair: b.config.Comm.SSH.SSHTemporaryKeyPair,
},
multistep.If(genTempKeyPair,
&communicator.StepSSHKeyGen{
CommConf: &b.config.Comm,
SSHTemporaryKeyPair: b.config.Comm.SSH.SSHTemporaryKeyPair,
},
),
multistep.If(b.config.PackerDebug && b.config.Comm.SSHPrivateKeyFile == "",
&communicator.StepDumpSSHKey{
Path: fmt.Sprintf("do_%s.pem", b.config.PackerBuildName),
SSH: &b.config.Comm.SSH,
},
),
&stepCreateSSHKey{},
multistep.If(genTempKeyPair, new(stepCreateSSHKey)),
new(stepCreateDroplet),
new(stepDropletInfo),
&communicator.StepConnect{
Expand All @@ -123,9 +128,11 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
SSHConfig: b.config.Comm.SSHConfigFunc(),
},
new(commonsteps.StepProvision),
&commonsteps.StepCleanupTempKeys{
Comm: &b.config.Comm,
},
multistep.If(genTempKeyPair,
&commonsteps.StepCleanupTempKeys{
Comm: &b.config.Comm,
},
),
new(stepShutdown),
new(stepPowerOff),
&stepSnapshot{
Expand Down

0 comments on commit 82bd5c8

Please sign in to comment.