Skip to content

Commit 02fce85

Browse files
committed
added ability to use fixed template per config
1 parent c3b2bc6 commit 02fce85

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

builder/upcloud/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ type Config struct {
4949
StorageName string `mapstructure:"storage_name"`
5050

5151
// Optional configuration values
52-
TemplatePrefix string `mapstructure:"template_prefix"`
53-
StorageSize int `mapstructure:"storage_size"`
54-
Timeout time.Duration `mapstructure:"state_timeout_duration"`
55-
CloneZones []string `mapstructure:"clone_zones"`
52+
TemplatePrefix string `mapstructure:"template_prefix"`
53+
IsTemplateNameFixed bool `mapstructure:"is_template_name_fixed"`
54+
StorageSize int `mapstructure:"storage_size"`
55+
Timeout time.Duration `mapstructure:"state_timeout_duration"`
56+
CloneZones []string `mapstructure:"clone_zones"`
5657

5758
RawNetworking []internal.NetworkInterface `mapstructure:"network_interfaces"`
5859
Networking []request.CreateServerInterface

builder/upcloud/step_create_template.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ func (s *StepCreateTemplate) Run(_ context.Context, state multistep.StateBag) mu
5353
for _, uuid := range storageUuids {
5454
ui.Say(fmt.Sprintf("Creating template for storage %q...", uuid))
5555

56-
t, err := driver.CreateTemplate(uuid, s.Config.TemplatePrefix)
56+
templateTitle := s.Config.TemplatePrefix
57+
if !s.Config.IsTemplateNameFixed {
58+
templateTitle = fmt.Sprintf("%s-%s", templateTitle, internal.GetNowString())
59+
}
60+
61+
t, err := driver.CreateTemplate(uuid, templateTitle)
5762
if err != nil {
5863
return internal.StepHaltWithError(state, err)
5964
}
65+
6066
templates = append(templates, t)
6167
ui.Say(fmt.Sprintf("Template for storage %q created...", uuid))
6268
}

internal/driver.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ func (d *driver) StopServer(serverUuid string) error {
113113
return nil
114114
}
115115

116-
func (d *driver) CreateTemplate(serverStorageUuid, prefix string) (*upcloud.Storage, error) {
116+
func (d *driver) CreateTemplate(serverStorageUuid, templateTitle string) (*upcloud.Storage, error) {
117117
// create image
118-
templateTitle := fmt.Sprintf("%s-%s", prefix, GetNowString())
119118
response, err := d.svc.TemplatizeStorage(&request.TemplatizeStorageRequest{
120119
UUID: serverStorageUuid,
121120
Title: templateTitle,

0 commit comments

Comments
 (0)