When creating a new VApp wait for the VM to be given an IP address if using DHCP
This commit is contained in:
parent
0d9a7a65ef
commit
04d7532bf7
|
@ -297,17 +297,45 @@ func resourceVcdVAppRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
return fmt.Errorf("Error refreshing vdc: %#v", err)
|
return fmt.Errorf("Error refreshing vdc: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id())
|
_, err = vcdClient.OrgVdc.FindVAppByName(d.Id())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[DEBUG] Unable to find vapp. Removing from tfstate")
|
log.Printf("[DEBUG] Unable to find vapp. Removing from tfstate")
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
d.Set("ip", vapp.VApp.Children.VM[0].NetworkConnectionSection.NetworkConnection.IPAddress)
|
|
||||||
|
ip, err := getVAppIPAddress(d, meta)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.Set("ip", ip)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getVAppIPAddress(d *schema.ResourceData, meta interface{}) (string, error) {
|
||||||
|
vcdClient := meta.(*VCDClient)
|
||||||
|
var ip string
|
||||||
|
|
||||||
|
err := retryCall(vcdClient.MaxRetryTimeout, func() error {
|
||||||
|
err := vcdClient.OrgVdc.Refresh()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error refreshing vdc: %#v", err)
|
||||||
|
}
|
||||||
|
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Unable to find vapp.")
|
||||||
|
}
|
||||||
|
ip = vapp.VApp.Children.VM[0].NetworkConnectionSection.NetworkConnection.IPAddress
|
||||||
|
if ip == "" {
|
||||||
|
return fmt.Errorf("Timeout: VM did not aquire IP address")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return ip, err
|
||||||
|
}
|
||||||
|
|
||||||
func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
vcdClient := meta.(*VCDClient)
|
vcdClient := meta.(*VCDClient)
|
||||||
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id())
|
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id())
|
||||||
|
|
Loading…
Reference in New Issue