Last active
May 15, 2017 05:46
-
-
Save jtopjian/7f9efea8647b05278de040a6a91c8616 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func resourceComputeFloatingIPAssociateV2Read(d *schema.ResourceData, meta interface{}) error { | |
config := meta.(*Config) | |
computeClient, err := config.computeV2Client(GetRegion(d)) | |
if err != nil { | |
return fmt.Errorf("Error creating OpenStack compute client: %s", err) | |
} | |
// Obtain relevant info from parsing the ID | |
floatingIP, instanceId, fixedIP, err := parseComputeFloatingIPAssociateId(d.Id()) | |
if err != nil { | |
return err | |
} | |
d.Set("floating_ip", floatingIP) | |
d.Set("instance_id", instanceId) | |
d.Set("fixed_ip", fixedIP) | |
d.Set("region", GetRegion(d)) | |
// check whether floatingIP or associated instance deleted | |
allPages, err := floatingips.List(computeClient).AllPages() | |
if err != nil { | |
return err | |
} | |
allFips, err := floatingips.ExtractFloatingIPs(allPages) | |
if err != nil { | |
return err | |
} | |
var fip floatingips.FloatingIP | |
var found bool | |
for _, f := range allFips { | |
if f.IP == floatingIP { | |
fip = f | |
found = true | |
} | |
} | |
if !found { | |
d.SetId("") | |
} | |
if fip.InstanceID == "" { | |
d.SetId("") | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment