Just try the first IP available if none found before

Some cloud don't implement correctly IP addresses.
Instead of failing during the provisionning, we just take the
first IP available and try with this one.
This commit is contained in:
Julien Vey 2015-02-04 22:14:36 +01:00 committed by Jon Perritt
parent ccd51ae3ab
commit 8e9c6787dd
1 changed files with 15 additions and 1 deletions

View File

@ -246,11 +246,25 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err
pa := paRaw.(map[string]interface{}) pa := paRaw.(map[string]interface{})
if pa["version"].(float64) == 4 { if pa["version"].(float64) == 4 {
host = pa["addr"].(string) host = pa["addr"].(string)
break
}
}
}
}
// If no host found, just get the first IP we find
if host == "" {
for _, networkAddresses := range server.Addresses {
for _, element := range networkAddresses.([]interface{}) {
address := element.(map[string]interface{})
if address["version"].(float64) == 4 {
host = address["addr"].(string)
break
}
}
}
}
d.Set("access_ip_v4", host) d.Set("access_ip_v4", host)
}
}
}
}
d.Set("host", host) d.Set("host", host)
log.Printf("host: %s", host) log.Printf("host: %s", host)