aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRavi Shekhar Jethani <rsjethani@gmail.com>2017-09-16 02:33:35 +0530
committerRavi Shekhar Jethani <rsjethani@gmail.com>2017-09-16 02:33:35 +0530
commit79d6d592b80a138ddd167fcb66ccf3043c3c07bd (patch)
tree1df9b5d3bda0dd48d3b524df8b2e87113f9ca9ed
parent23635373aed10aab286a2436459670b686b581bb (diff)
downloadterraform-provider-libvirt-79d6d592b80a138ddd167fcb66ccf3043c3c07bd.tar
terraform-provider-libvirt-79d6d592b80a138ddd167fcb66ccf3043c3c07bd.tar.gz
FIX waitForLeases invalid key issue
We are modifying network interface object after adding it as key to waitForLeases map. This makes the interface object stored in the key invalid when it is used in functions like hasNetworkAddress() later. As a result of this the code does not wait for the interface to get the lease even after specifying `wait_for_lease = true` in the tf file. To fix this we move the code to add interface struct object to waitForLeases map only after all modifications are done i.e. near to the end of for loop.
-rw-r--r--libvirt/resource_libvirt_domain.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go
index 571b7359..40a62687 100644
--- a/libvirt/resource_libvirt_domain.go
+++ b/libvirt/resource_libvirt_domain.go
@@ -484,12 +484,6 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
Address: mac,
}
- // this is not passed to libvirt, but used by waitForAddress
- waitForLeases[netIface] = false
- if waitForLease, ok := d.GetOk(prefix + ".wait_for_lease"); ok {
- waitForLeases[netIface] = waitForLease.(bool)
- }
-
// connect to the interface to the network... first, look for the network
if n, ok := d.GetOk(prefix + ".network_name"); ok {
// when using a "network_name" we do not try to do anything: we just
@@ -537,8 +531,11 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
} else {
// no IPs provided: if the hostname has been provided, wait until we get an IP
if len(hostname) > 0 {
- if !waitForLeases[netIface] {
- return fmt.Errorf("Cannot map '%s': we are not waiting for lease and no IP has been provided", hostname)
+ if waitForLeaseI, ok := d.GetOk(prefix + ".wait_for_lease"); ok {
+ waitForLease := waitForLeaseI.(bool)
+ if !waitForLease {
+ return fmt.Errorf("Cannot map '%s': we are not waiting for lease and no IP has been provided", hostname)
+ }
}
// the resource specifies a hostname but not an IP, so we must wait until we
// have a valid lease and then read the IP we have been assigned, so we can
@@ -583,6 +580,11 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
} else {
// no network has been specified: we are on our own
}
+ // this is not passed to libvirt, but used by waitForAddress
+ waitForLeases[netIface] = false
+ if waitForLease, ok := d.GetOk(prefix + ".wait_for_lease"); ok {
+ waitForLeases[netIface] = waitForLease.(bool)
+ }
netIfaces = append(netIfaces, netIface)
}