Skip to content

Commit 59da38e

Browse files
committed
feat: add server_plan parameter
1 parent 309c846 commit 59da38e

File tree

10 files changed

+44
-8
lines changed

10 files changed

+44
-8
lines changed

.web-docs/components/builder/upcloud/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The upcloud builder is used to generate storage templates on UpCloud.
3636

3737
- `token` (string) - The API token to use when interfacing with the UpCloud API. This is mutually exclusive with username and password.
3838

39+
- `server_plan` (string) - Server plan to use for the builder server. Defaults to `1xCPU-2GB`.
40+
3941
- `storage_name` (string) - The name of the storage that will be used to find the first matching storage in the list of existing templates.
4042

4143
Note that `storage_uuid` parameter has higher priority. You should use either `storage_uuid` or `storage_name` for not strict matching (e.g "ubuntu server 24.04").

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- `server_plan` parameter to builder configuration for selecting server plan to use during build.
11+
812
## [1.9.2] - 2025-10-16
913

1014
### Changed

builder/upcloud/builder_acc_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ var testBuilderStorageName string
3838
//go:embed test-fixtures/json/networking.json
3939
var testBuilderNetworking string
4040

41-
//go:embed test-fixtures/json/basic_standard_tier.json
42-
var testBuilderBasicStandardTier string
41+
//go:embed test-fixtures/json/plan_and_tier.json
42+
var testBuilderPlanAndTier string
4343

4444
func TestBuilderAcc_default(t *testing.T) {
4545
t.Parallel()
@@ -78,12 +78,12 @@ func TestBuilderAcc_storageName(t *testing.T) {
7878
acctest.TestPlugin(t, testCase)
7979
}
8080

81-
func TestBuilderAcc_standardTier(t *testing.T) {
81+
func TestBuilderAcc_planAndTier(t *testing.T) {
8282
t.Parallel()
8383
testAccPreCheck(t)
8484
testCase := &acctest.PluginTestCase{
8585
Name: t.Name(),
86-
Template: testBuilderBasicStandardTier,
86+
Template: testBuilderPlanAndTier,
8787
Check: checkTestResult(t),
8888
Teardown: teardown(t, t.Name()),
8989
}
@@ -107,6 +107,9 @@ func TestBuilderAcc_networking(t *testing.T) {
107107
//go:embed test-fixtures/hcl2/basic.pkr.hcl
108108
var testBuildBasicHcl string
109109

110+
//go:embed test-fixtures/hcl2/plan_and_tier.pkr.hcl
111+
var testBuilderPlanAndTierHcl string
112+
110113
//go:embed test-fixtures/hcl2/storage-uuid.pkr.hcl
111114
var testBuilderStorageUUIDHcl string
112115

@@ -128,6 +131,18 @@ func TestBuilderAcc_default_hcl(t *testing.T) {
128131
acctest.TestPlugin(t, testCase)
129132
}
130133

134+
func TestBuilderAcc_planAndTier_hcl(t *testing.T) {
135+
t.Parallel()
136+
testAccPreCheck(t)
137+
testCase := &acctest.PluginTestCase{
138+
Name: t.Name(),
139+
Template: testBuilderPlanAndTierHcl,
140+
Check: checkTestResult(t),
141+
Teardown: teardown(t, t.Name()),
142+
}
143+
acctest.TestPlugin(t, testCase)
144+
}
145+
131146
func TestBuilderAcc_storageUuid_hcl(t *testing.T) {
132147
t.Parallel()
133148
testAccPreCheck(t)
@@ -152,7 +167,7 @@ func TestBuilderAcc_storageName_hcl(t *testing.T) {
152167
acctest.TestPlugin(t, testCase)
153168
}
154169

155-
func TestBuilderAcc_network_interfaces(t *testing.T) {
170+
func TestBuilderAcc_network_interfaces_hcl(t *testing.T) {
156171
t.Parallel()
157172
testAccPreCheck(t)
158173
testCase := &acctest.PluginTestCase{

builder/upcloud/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ type Config struct {
7474
// The zone in which the server and template should be created (e.g. nl-ams1).
7575
Zone string `mapstructure:"zone" required:"true"`
7676

77+
// Server plan to use for the builder server. Defaults to `1xCPU-2GB`.
78+
ServerPlan string `mapstructure:"server_plan"`
79+
7780
// The UUID of the storage you want to use as a template when creating the server.
7881
//
7982
// Optionally use `storage_name` parameter to find matching storage

builder/upcloud/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/upcloud/step_create_server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func (s *StepCreateServer) createServer(ctx context.Context, ui packer.Ui, drv d
9393
}
9494

9595
response, err := drv.CreateServer(ctx, &driver.ServerOpts{
96+
ServerPlan: s.Config.ServerPlan,
9697
StorageUUID: storage.UUID,
9798
StorageSize: s.Config.StorageSize,
9899
Zone: s.Config.Zone,

builder/upcloud/test-fixtures/hcl2/basic_standard_tier.hcl renamed to builder/upcloud/test-fixtures/hcl2/plan_and_tier.pkr.hcl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
source "upcloud" "standard-tier" {
2+
server_plan = "2xCPU-4GB"
23
storage_uuid = "01000000-0000-4000-8000-000150020100" # Rocky Linux 9
3-
zone = "pl-waw1"
44
storage_tier = "standard"
5+
zone = "pl-waw1"
56
}
67

78
build {
89
sources = ["source.upcloud.standard-tier"]
9-
}
10+
}

builder/upcloud/test-fixtures/json/basic_standard_tier.json renamed to builder/upcloud/test-fixtures/json/plan_and_tier.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"builders": [{
33
"type": "upcloud",
44
"zone": "nl-ams1",
5+
"server_plan": "2xCPU-4GB",
56
"storage_uuid": "01000000-0000-4000-8000-000150020100",
67
"storage_tier": "standard"
78
}]

docs-partials/builder/upcloud/Config-not-required.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
- `token` (string) - The API token to use when interfacing with the UpCloud API. This is mutually exclusive with username and password.
88

9+
- `server_plan` (string) - Server plan to use for the builder server. Defaults to `1xCPU-2GB`.
10+
911
- `storage_name` (string) - The name of the storage that will be used to find the first matching storage in the list of existing templates.
1012

1113
Note that `storage_uuid` parameter has higher priority. You should use either `storage_uuid` or `storage_name` for not strict matching (e.g "ubuntu server 24.04").

internal/driver/driver.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type (
8282
}
8383

8484
ServerOpts struct {
85+
ServerPlan string
8586
StorageUUID string
8687
StorageSize int
8788
Zone string
@@ -409,13 +410,17 @@ func (d *driver) GetServerStorage(ctx context.Context, serverUUID string) (*upcl
409410
func (d *driver) prepareCreateRequest(opts *ServerOpts) *request.CreateServerRequest {
410411
title := fmt.Sprintf("packer-%s-%s", DefaultHostname, getNowString())
411412
titleDisk := fmt.Sprintf("%s-disk1", DefaultHostname)
413+
plan := opts.ServerPlan
414+
if plan == "" {
415+
plan = DefaultPlan
416+
}
412417

413418
request := request.CreateServerRequest{
414419
Title: title,
415420
Hostname: DefaultHostname,
416421
Zone: opts.Zone,
417422
PasswordDelivery: request.PasswordDeliveryNone,
418-
Plan: DefaultPlan,
423+
Plan: plan,
419424
StorageDevices: []request.CreateServerStorageDevice{
420425
{
421426
Action: request.CreateServerStorageDeviceActionClone,

0 commit comments

Comments
 (0)