Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/digitalocean: Fixing panic condition on FloatingIP droplet #4214

Merged
merged 1 commit into from Dec 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -83,8 +83,10 @@ func resourceDigitalOceanFloatingIpRead(d *schema.ResourceData, meta interface{}
}

if _, ok := d.GetOk("droplet_id"); ok {
log.Printf("[INFO] The region of the Droplet is %s", floatingIp.Droplet.Region)
d.Set("region", floatingIp.Droplet.Region.Slug)
if floatingIp.Droplet != nil {
log.Printf("[INFO] The region of the Droplet is %s", floatingIp.Droplet.Region)
d.Set("region", floatingIp.Droplet.Region.Slug)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, this skips setting the region at all if the floating IP exits but the droplet doesn't. It seems like we could fall back to the below else case, but not sure what the ramifications are.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good point, we should probably check this explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franklinhu the current tests for this are for both region based floatingips and floatingips with droplets. A floatingIP must either be created for a region OR a droplet. So if we fall back to the region then that seems to be the correct course of action

I haven't been able to trigger the panic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franklinhu ok, I just sent #4216. To be more explicit. I don't rely on the d.GetOk anymore. I use the API result directly and then check for a droplet and use the region that way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah awesome thanks!

} else {
d.Set("region", floatingIp.Region.Slug)
}
Expand Down