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

r/aws_eip: Do not disassociate on tags-only update #2975

Merged
merged 2 commits into from
Jan 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,33 @@ func resourceAwsEipUpdate(d *schema.ResourceData, meta interface{}) error {

domain := resourceAwsEipDomain(d)

// Associate to instance or interface if specified
v_instance, ok_instance := d.GetOk("instance")
v_interface, ok_interface := d.GetOk("network_interface")

// If we are updating an EIP that is not newly created, and we are attached to
// an instance or interface, detach first.
if (d.Get("instance").(string) != "" || d.Get("association_id").(string) != "") && !d.IsNewResource() {
disassociate := false
if !d.IsNewResource() {
if d.HasChange("instance") && d.Get("instance").(string) != "" {
disassociate = true
} else if (d.HasChange("network_interface") || d.HasChange("associate_with_private_ip")) && d.Get("association_id").(string) != "" {
disassociate = true
}
}
if disassociate {
if err := disassociateEip(d, meta); err != nil {
return err
}
}

if ok_instance || ok_interface {
// Associate to instance or interface if specified
associate := false
v_instance, ok_instance := d.GetOk("instance")
v_interface, ok_interface := d.GetOk("network_interface")

if d.HasChange("instance") && ok_instance {
associate = true
} else if (d.HasChange("network_interface") || d.HasChange("associate_with_private_ip")) && ok_interface {
associate = true
}
if associate {
instanceId := v_instance.(string)
networkInterfaceId := v_interface.(string)

Expand Down