Skip to content

Commit 6083329

Browse files
author
Sander van Harmelen
committed
Merge pull request hashicorp#2481 from svanharmelen/b-provider-cloudstack-userdata
provider/cloudstack: update userdata size check
2 parents 0d36c24 + b7b770d commit 6083329

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

builtin/providers/cloudstack/resource_cloudstack_instance.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,16 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
166166
// If the user data contains any info, it needs to be base64 encoded and
167167
// added to the parameter struct
168168
if userData, ok := d.GetOk("user_data"); ok {
169-
//deployVirtualMachine uses POST, so max userdata is 32K
170-
//https://github.com/xanzy/go-cloudstack/commit/c767de689df1faedfec69233763a7c5334bee1f6
171-
if len(userData.(string)) > 32768 {
169+
ud := base64.StdEncoding.EncodeToString([]byte(userData.(string)))
170+
171+
// deployVirtualMachine uses POST, so max userdata is 32K
172+
// https://github.com/xanzy/go-cloudstack/commit/c767de689df1faedfec69233763a7c5334bee1f6
173+
if len(ud) > 32768 {
172174
return fmt.Errorf(
173-
"The supplied user_data contains %d bytes before encoding, "+
174-
"this exeeds the limit of 32768 bytes", len(userData.(string)))
175+
"The supplied user_data contains %d bytes after encoding, "+
176+
"this exeeds the limit of 32768 bytes", len(ud))
175177
}
176-
ud := base64.StdEncoding.EncodeToString([]byte(userData.(string)))
178+
177179
p.SetUserdata(ud)
178180
}
179181

0 commit comments

Comments
 (0)