Skip to content

Commit

Permalink
Allow to specify user_data in a template
Browse files Browse the repository at this point in the history
For some cases relying on a script to be passed to shell
provisioner is not enough. So let's allow user to specify
actual userdata to be passed to the vm on creation, this
will help in complex scenarios like persistently changing
network routing that will survive reboots.
  • Loading branch information
fernflower committed Jan 20, 2025
1 parent 1d6a6ae commit f2ad4b1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions builder/powervs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
&StepCreateInstance{
InstanceName: b.config.InstanceName,
KeyPairName: b.config.KeyPairName,
UserData: b.config.UserData,
},
&communicator.StepConnect{
Config: &b.config.RunConfig.Comm,
Expand Down
2 changes: 2 additions & 0 deletions builder/powervs/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions builder/powervs/common/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type RunConfig struct {
InstanceName string `mapstructure:"instance_name" required:"true"`
KeyPairName string `mapstructure:"key_pair_name" required:"true"`
SubnetIDs []string `mapstructure:"subnet_ids" required:"false"`
UserData string `mapstructure:"user_data" required:"false"`
DHCPNetwork bool `mapstructure:"dhcp_network" required:"false"`
Source Source `mapstructure:"source" required:"true"`
Capture Capture `mapstructure:"capture" required:"true"`
Expand Down
3 changes: 3 additions & 0 deletions builder/powervs/step_create_instance.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package powervs

import (
b64 "encoding/base64"
"context"
"fmt"
"time"
Expand All @@ -15,6 +16,7 @@ import (
type StepCreateInstance struct {
InstanceName string
KeyPairName string
UserData string

doCleanup bool
}
Expand Down Expand Up @@ -54,6 +56,7 @@ func (s *StepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu
Processors: core.Float64Ptr(0.5),
ServerName: &s.InstanceName,
StorageType: *imageRef.StorageType,
UserData: b64.StdEncoding.EncodeToString([]byte(s.UserData)),
}
ui.Message("Creating Instance")
ins, err := instanceClient.Create(body)
Expand Down

0 comments on commit f2ad4b1

Please sign in to comment.