From 2b28a82f84be9aa833d8c733457abfd98ecb74ee Mon Sep 17 00:00:00 2001 From: David Underwood Date: Tue, 20 Feb 2024 11:43:22 -0500 Subject: [PATCH 1/2] WIP: Adds config flag for skipping SSH keygen --- builder/digitalocean/builder.go | 2 +- builder/digitalocean/config.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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 } From 7620b5ba6494af6377c0e8ed5e671043ec152a71 Mon Sep 17 00:00:00 2001 From: David Underwood Date: Tue, 20 Feb 2024 13:34:01 -0500 Subject: [PATCH 2/2] Fixes config error with proper code generation --- .web-docs/components/builder/digitalocean/README.md | 3 +++ builder/digitalocean/config.hcl2spec.go | 2 ++ docs-partials/builder/digitalocean/Config-not-required.mdx | 3 +++ 3 files changed, 8 insertions(+) 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/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. +