From b7b770d0dae911abbb926c45fe9e96294bfd35f7 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 25 Jun 2015 09:45:39 +0200 Subject: [PATCH] Update user date size check This makes sure we check the right thing. --- .../cloudstack/resource_cloudstack_instance.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/builtin/providers/cloudstack/resource_cloudstack_instance.go b/builtin/providers/cloudstack/resource_cloudstack_instance.go index 44a03f867..2c434f53c 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_instance.go +++ b/builtin/providers/cloudstack/resource_cloudstack_instance.go @@ -166,14 +166,16 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{}) // If the user data contains any info, it needs to be base64 encoded and // added to the parameter struct if userData, ok := d.GetOk("user_data"); ok { - //deployVirtualMachine uses POST, so max userdata is 32K - //https://github.com/xanzy/go-cloudstack/commit/c767de689df1faedfec69233763a7c5334bee1f6 - if len(userData.(string)) > 32768 { - return fmt.Errorf( - "The supplied user_data contains %d bytes before encoding, "+ - "this exeeds the limit of 32768 bytes", len(userData.(string))) - } ud := base64.StdEncoding.EncodeToString([]byte(userData.(string))) + + // deployVirtualMachine uses POST, so max userdata is 32K + // https://github.com/xanzy/go-cloudstack/commit/c767de689df1faedfec69233763a7c5334bee1f6 + if len(ud) > 32768 { + return fmt.Errorf( + "The supplied user_data contains %d bytes after encoding, "+ + "this exeeds the limit of 32768 bytes", len(ud)) + } + p.SetUserdata(ud) }