Skip to content

Commit

Permalink
Merge pull request #118 from pragnesh/main
Browse files Browse the repository at this point in the history
if ssh_key_id is specified don't import ssh public key
  • Loading branch information
andrewsomething authored Dec 11, 2023
2 parents 7c1135a + 82bd5c8 commit 4a4ee95
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 4a4ee95

Please sign in to comment.