From 0092946f748f77770e7807d16f6c3e48ae6b14d1 Mon Sep 17 00:00:00 2001 From: Chris Buben Date: Fri, 20 Mar 2015 18:55:42 -0400 Subject: [PATCH] user_data support Mostly stolen from: https://github.com/jtopjian/terraform-provider-openstack/blob/master/openstack/resource_openstack_instance.go --- .../resource_openstack_compute_instance_v2.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go index 63508ffa7..5a4c16c7e 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go @@ -2,6 +2,8 @@ package openstack import ( "bytes" + "crypto/sha1" + "encoding/hex" "fmt" "log" "time" @@ -75,6 +77,21 @@ func resourceComputeInstanceV2() *schema.Resource { Optional: true, ForceNew: false, }, + "user_data": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + // just stash the hash for state & diff comparisons + StateFunc: func(v interface{}) string { + switch v.(type) { + case string: + hash := sha1.Sum([]byte(v.(string))) + return hex.EncodeToString(hash[:]) + default: + return "" + } + }, + }, "security_groups": &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -224,6 +241,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e Metadata: resourceInstanceMetadataV2(d), ConfigDrive: d.Get("config_drive").(bool), AdminPass: d.Get("admin_pass").(string), + UserData: []byte(d.Get("user_data").(string)), } if keyName, ok := d.Get("key_pair").(string); ok && keyName != "" {