aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Hipp <thipp@suse.de>2017-08-08 10:56:51 +0200
committerFlavio Castelli <flavio@castelli.me>2017-08-08 11:31:45 +0200
commitd9c8d155c800a120c7f53931de002bb8220b80d3 (patch)
treeb6f7e2f45834002cd75177cc731f792433cab773
parent51fbd4082fba1797cc33b77b2a31f99bafd9be4a (diff)
downloadterraform-provider-libvirt-d9c8d155c800a120c7f53931de002bb8220b80d3.tar
terraform-provider-libvirt-d9c8d155c800a120c7f53931de002bb8220b80d3.tar.gz
cloudinit: show user_data in .tfstate file
This fixes #135. Signed-off-by: Thomas Hipp <thipp@suse.de>
-rw-r--r--libvirt/cloudinit_def.go6
-rw-r--r--libvirt/resource_cloud_init.go7
2 files changed, 9 insertions, 4 deletions
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])
}