Skip to content

Commit 5fe6132

Browse files
authored
Merge pull request #72 from IBM/vsi-userdata-support
User data support as string
2 parents 96508fa + 8104725 commit 5fe6132

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ vsi_interface | string | Set it as "public" to create a Floating IP to connect t
200200
| |
201201
| |
202202
vsi_user_data_file | string | User data to be made available when setting up the virtual server instance. Optional.
203+
| OR |
204+
vsi_user_data | string | User data to be made available when setting up the virtual server instance. Optional. This is the string input variable.
203205
vpc_endpoint_url | string | Configure URL for VPC test environments. Optional.
204206
iam_url | string | Configure URL for IAM test environments. Optional.
205207
image_name | string | The name of the resulting custom Image that will appear in your account. Required.

builder/ibmcloud/vpc/config.go

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Config struct {
3535
VSIProfile string `mapstructure:"vsi_profile"`
3636
VSIInterface string `mapstructure:"vsi_interface"`
3737
VSIUserDataFile string `mapstructure:"vsi_user_data_file"`
38+
VSIUserDataString string `mapstructure:"vsi_user_data"`
3839

3940
ImageName string `mapstructure:"image_name"`
4041

@@ -105,6 +106,12 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
105106
c.VSIInterface = "public"
106107
}
107108

109+
// Check for mutual exclusion of User data input via file or as a string.
110+
if c.VSIUserDataFile != "" && c.VSIUserDataString != "" {
111+
errs = packer.MultiErrorAppend(
112+
errs, errors.New("mutual exclusion: User data input, either a file as in vsi_user_data_file could be used or a string in vsi_user_data_string, together are not supported"))
113+
}
114+
108115
if c.VSIUserDataFile != "" {
109116
if _, err := os.Stat(c.VSIUserDataFile); os.IsNotExist(err) {
110117
errs = packer.MultiErrorAppend(

builder/ibmcloud/vpc/config.hcl2spec.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/ibmcloud/vpc/step_create_instance.go

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (step *stepCreateInstance) Run(_ context.Context, state multistep.StateBag)
7777
instancePrototypeModel.CatalogOffering = catalogOfferingPrototype
7878

7979
userDataFilePath := config.VSIUserDataFile
80+
userDataString := config.VSIUserDataString
8081
if userDataFilePath != "" {
8182
content, err := ioutil.ReadFile(userDataFilePath)
8283
if err != nil {
@@ -86,6 +87,8 @@ func (step *stepCreateInstance) Run(_ context.Context, state multistep.StateBag)
8687
return multistep.ActionHalt
8788
}
8889
instancePrototypeModel.UserData = &[]string{string(content)}[0]
90+
} else if userDataString != "" {
91+
instancePrototypeModel.UserData = &[]string{string(userDataString)}[0]
8992
}
9093

9194
if config.ResourceGroupID != "" {
@@ -152,6 +155,7 @@ func (step *stepCreateInstance) Run(_ context.Context, state multistep.StateBag)
152155
}
153156

154157
userDataFilePath := config.VSIUserDataFile
158+
userDataString := config.VSIUserDataString
155159
if userDataFilePath != "" {
156160
content, err := ioutil.ReadFile(userDataFilePath)
157161
if err != nil {
@@ -161,6 +165,8 @@ func (step *stepCreateInstance) Run(_ context.Context, state multistep.StateBag)
161165
return multistep.ActionHalt
162166
}
163167
instancePrototypeModel.UserData = &[]string{string(content)}[0]
168+
} else if userDataString != "" {
169+
instancePrototypeModel.UserData = &[]string{string(userDataString)}[0]
164170
}
165171

166172
if config.ResourceGroupID != "" {

version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var IBMCloudPluginVersion *version.PluginVersion
88

99
var (
1010
// Version is the main version number that is being run at the moment.
11-
Version = "v3.1.0"
11+
Version = "v3.1.1"
1212
VersionPrerelease = "dev"
1313
)
1414

0 commit comments

Comments
 (0)