diff --git a/.web-docs/components/builder/digitalocean/README.md b/.web-docs/components/builder/digitalocean/README.md index 514c4ee..a0ee304 100644 --- a/.web-docs/components/builder/digitalocean/README.md +++ b/.web-docs/components/builder/digitalocean/README.md @@ -117,6 +117,9 @@ each category, the available configuration keys are alphabetized. - `ssh_key_id` (int) - The ID of an existing SSH key on the DigitalOcean account. This should be used in conjunction with `ssh_private_key_file`. +- `skip_keygen` (bool) - Set to true if you are connecting as a non-root user whose public key is + already available on the base image. + diff --git a/builder/digitalocean/builder.go b/builder/digitalocean/builder.go index e2383ed..b420439 100644 --- a/builder/digitalocean/builder.go +++ b/builder/digitalocean/builder.go @@ -103,7 +103,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.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 == "" + genTempKeyPair := !b.config.SkipKeygen && (b.config.SSHKeyID == 0 || b.config.Comm.SSHPrivateKeyFile == "") // Build the steps steps := []multistep.Step{ diff --git a/builder/digitalocean/config.go b/builder/digitalocean/config.go index 06813a1..dcdfd5d 100644 --- a/builder/digitalocean/config.go +++ b/builder/digitalocean/config.go @@ -114,6 +114,9 @@ type Config struct { // The ID of an existing SSH key on the DigitalOcean account. This should be // used in conjunction with `ssh_private_key_file`. SSHKeyID int `mapstructure:"ssh_key_id" required:"false"` + // Set to true if you are connecting as a non-root user whose public key is + // already available on the base image. + SkipKeygen bool `mapstructure:"skip_keygen" required:"false"` ctx interpolate.Context } diff --git a/builder/digitalocean/config.hcl2spec.go b/builder/digitalocean/config.hcl2spec.go index abb1871..a9add30 100644 --- a/builder/digitalocean/config.hcl2spec.go +++ b/builder/digitalocean/config.hcl2spec.go @@ -92,6 +92,7 @@ type FlatConfig struct { VPCUUID *string `mapstructure:"vpc_uuid" required:"false" cty:"vpc_uuid" hcl:"vpc_uuid"` ConnectWithPrivateIP *bool `mapstructure:"connect_with_private_ip" required:"false" cty:"connect_with_private_ip" hcl:"connect_with_private_ip"` SSHKeyID *int `mapstructure:"ssh_key_id" required:"false" cty:"ssh_key_id" hcl:"ssh_key_id"` + SkipKeygen *bool `mapstructure:"skip_keygen" required:"false" cty:"skip_keygen" hcl:"skip_keygen"` } // FlatMapstructure returns a new FlatConfig. @@ -188,6 +189,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "vpc_uuid": &hcldec.AttrSpec{Name: "vpc_uuid", Type: cty.String, Required: false}, "connect_with_private_ip": &hcldec.AttrSpec{Name: "connect_with_private_ip", Type: cty.Bool, Required: false}, "ssh_key_id": &hcldec.AttrSpec{Name: "ssh_key_id", Type: cty.Number, Required: false}, + "skip_keygen": &hcldec.AttrSpec{Name: "skip_keygen", Type: cty.Bool, Required: false}, } return s } diff --git a/docs-partials/builder/digitalocean/Config-not-required.mdx b/docs-partials/builder/digitalocean/Config-not-required.mdx index db1195b..1728d0c 100644 --- a/docs-partials/builder/digitalocean/Config-not-required.mdx +++ b/docs-partials/builder/digitalocean/Config-not-required.mdx @@ -71,4 +71,7 @@ - `ssh_key_id` (int) - The ID of an existing SSH key on the DigitalOcean account. This should be used in conjunction with `ssh_private_key_file`. +- `skip_keygen` (bool) - Set to true if you are connecting as a non-root user whose public key is + already available on the base image. +