From c8c1230483fa1ffc615f71bf887f5bbcedd312e1 Mon Sep 17 00:00:00 2001 From: Anton Dalgren Date: Thu, 18 Sep 2025 15:08:52 +0200 Subject: [PATCH] Launch droplet in a specific project depends on: https://github.com/digitalocean/godo/pull/881 --- .web-docs/components/builder/digitalocean/README.md | 2 ++ builder/digitalocean/config.go | 2 ++ builder/digitalocean/config.hcl2spec.go | 2 ++ builder/digitalocean/step_create_droplet.go | 2 ++ docs-partials/builder/digitalocean/Config-not-required.mdx | 2 ++ 5 files changed, 10 insertions(+) diff --git a/.web-docs/components/builder/digitalocean/README.md b/.web-docs/components/builder/digitalocean/README.md index 0be8ccbd..f48d0f36 100644 --- a/.web-docs/components/builder/digitalocean/README.md +++ b/.web-docs/components/builder/digitalocean/README.md @@ -119,6 +119,8 @@ 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`. +- `project_id` (string) - The Project ID to launch the droplet in. + diff --git a/builder/digitalocean/config.go b/builder/digitalocean/config.go index 7dec0653..cb0a6298 100644 --- a/builder/digitalocean/config.go +++ b/builder/digitalocean/config.go @@ -116,6 +116,8 @@ 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"` + // The Project ID to launch the droplet in. + ProjectID string `mapstructure:"project_id" required:"false"` ctx interpolate.Context } diff --git a/builder/digitalocean/config.hcl2spec.go b/builder/digitalocean/config.hcl2spec.go index 2338de77..0754ab91 100644 --- a/builder/digitalocean/config.hcl2spec.go +++ b/builder/digitalocean/config.hcl2spec.go @@ -93,6 +93,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"` + ProjectID *string `mapstructure:"project_id" required:"false" cty:"project_id" hcl:"project_id"` } // FlatMapstructure returns a new FlatConfig. @@ -190,6 +191,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}, + "project_id": &hcldec.AttrSpec{Name: "project_id", Type: cty.String, Required: false}, } return s } diff --git a/builder/digitalocean/step_create_droplet.go b/builder/digitalocean/step_create_droplet.go index 971bef41..4bbf62be 100644 --- a/builder/digitalocean/step_create_droplet.go +++ b/builder/digitalocean/step_create_droplet.go @@ -28,6 +28,7 @@ func (s *stepCreateDroplet) Run(ctx context.Context, state multistep.StateBag) m state.Put("droplet_size", c.Size) state.Put("droplet_name", c.DropletName) state.Put("build_region", c.Region) + state.Put("project_id", c.ProjectID) // Create the droplet based on configuration ui.Say("Creating droplet...") @@ -100,6 +101,7 @@ func (s *stepCreateDroplet) buildDropletCreateRequest(state multistep.StateBag) UserData: userData, Tags: c.Tags, VPCUUID: c.VPCUUID, + ProjectID: c.ProjectID, }, nil } diff --git a/docs-partials/builder/digitalocean/Config-not-required.mdx b/docs-partials/builder/digitalocean/Config-not-required.mdx index 4a461f15..c9adadcd 100644 --- a/docs-partials/builder/digitalocean/Config-not-required.mdx +++ b/docs-partials/builder/digitalocean/Config-not-required.mdx @@ -73,4 +73,6 @@ - `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`. +- `project_id` (string) - The Project ID to launch the droplet in. +