Skip to content

Commit 366e86f

Browse files
authored
feat(builder): add server_plan parameter (#185)
1 parent 2a4a764 commit 366e86f

File tree

14 files changed

+52
-16
lines changed

14 files changed

+52
-16
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/artifact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (a *Artifact) Files() []string {
3232
}
3333

3434
func (a *Artifact) Id() string { //nolint:revive // method is required by packer-plugin-sdk
35-
result := []string{}
35+
result := make([]string, 0, len(a.Templates))
3636
for _, t := range a.Templates {
3737
result = append(result, t.UUID)
3838
}

builder/upcloud/artifact_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestArtifact_Id(t *testing.T) {
2424
uuid2 := "some-uuid-2"
2525
expected := fmt.Sprintf("%s,%s", uuid1, uuid2)
2626

27-
templates := []*upcloud.Storage{}
27+
templates := make([]*upcloud.Storage, 0, 2)
2828
templates = append(templates, &upcloud.Storage{UUID: uuid1}, &upcloud.Storage{UUID: uuid2})
2929

3030
a := &Artifact{Templates: templates}
@@ -39,7 +39,7 @@ func TestArtifact_String(t *testing.T) {
3939
t.Parallel()
4040
expected := `Storage template created, UUID: some-uuid`
4141

42-
templates := []*upcloud.Storage{}
42+
templates := make([]*upcloud.Storage, 0, 1)
4343
templates = append(templates, &upcloud.Storage{UUID: "some-uuid"})
4444

4545
a := &Artifact{Templates: templates}
@@ -52,7 +52,7 @@ func TestArtifact_String(t *testing.T) {
5252

5353
func TestArtifact_Metadata(t *testing.T) {
5454
t.Parallel()
55-
templates := []*upcloud.Storage{}
55+
templates := make([]*upcloud.Storage, 0, 2)
5656
templates = append(templates,
5757
&upcloud.Storage{
5858
UUID: "some-uuid",

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
}]

0 commit comments

Comments
 (0)