From d9c8d155c800a120c7f53931de002bb8220b80d3 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Tue, 8 Aug 2017 10:56:51 +0200 Subject: cloudinit: show user_data in .tfstate file This fixes #135. Signed-off-by: Thomas Hipp --- libvirt/cloudinit_def.go | 6 ++++++ libvirt/resource_cloud_init.go | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'libvirt') diff --git a/libvirt/cloudinit_def.go b/libvirt/cloudinit_def.go index 243e7faf..4fc05507 100644 --- a/libvirt/cloudinit_def.go +++ b/libvirt/cloudinit_def.go @@ -273,6 +273,12 @@ func newCloudInitDefFromRemoteISO(virConn *libvirt.Connect, id string) (defCloud if err := yaml.Unmarshal(data, &ci.UserData); err != nil { return ci, fmt.Errorf("Error while unmarshalling user-data: %s", err) } + // This may differ from the user_data provided in the .tf file + // because it always includes ssh_authorized_keys. However, this + // shouldn't be an issue since both the authorized keys in the .tf + // file (field: ssh_authorized_key) and the ones in this userdata + // (field: ssh_authorized_keys) are the same. + ci.UserDataRaw = fmt.Sprintf("%s", data) } //TODO: the iso9660 has a bug... diff --git a/libvirt/resource_cloud_init.go b/libvirt/resource_cloud_init.go index b6a6851f..6221ebc5 100644 --- a/libvirt/resource_cloud_init.go +++ b/libvirt/resource_cloud_init.go @@ -89,15 +89,14 @@ func resourceCloudInitRead(d *schema.ResourceData, meta interface{}) error { } ci, err := newCloudInitDefFromRemoteISO(virConn, d.Id()) + if err != nil { + return fmt.Errorf("Error while retrieving remote ISO: %s", err) + } d.Set("pool", ci.PoolName) d.Set("name", ci.Name) d.Set("local_hostname", ci.Metadata.LocalHostname) d.Set("user_data", ci.UserDataRaw) - if err != nil { - return fmt.Errorf("Error while retrieving remote ISO: %s", err) - } - if len(ci.UserData.SSHAuthorizedKeys) == 1 { d.Set("ssh_authorized_key", ci.UserData.SSHAuthorizedKeys[0]) } -- cgit v1.2.3