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

Ignore missing ENI attachment when trying to detach ENI #7185

Merged
merged 1 commit into from
Jul 25, 2016

Conversation

Jonnymcc
Copy link
Contributor

When I taint an EC2 instance with an ENI attached, running terraform apply fails when trying to detach the ENI from the instance because the ENI attachment no longer exists. The ENI attachment disappears after deleting the EC2 instance. What this pull requests does is ignore the scenario where the ENI attachment is already gone, and should print the error if it is anything else.

Interestingly the ENI detachment method is very similar to the Volume attachment delete method

func resourceAwsVolumeAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
vID := d.Get("volume_id").(string)
iID := d.Get("instance_id").(string)
opts := &ec2.DetachVolumeInput{
Device: aws.String(d.Get("device_name").(string)),
InstanceId: aws.String(iID),
VolumeId: aws.String(vID),
Force: aws.Bool(d.Get("force_detach").(bool)),
}
_, err := conn.DetachVolume(opts)
stateConf := &resource.StateChangeConf{
Pending: []string{"detaching"},
Target: []string{"detached"},
Refresh: volumeAttachmentStateRefreshFunc(conn, vID, iID),
Timeout: 5 * time.Minute,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
log.Printf("[DEBUG] Detaching Volume (%s) from Instance (%s)", vID, iID)
_, err = stateConf.WaitForState()
if err != nil {
return fmt.Errorf(
"Error waiting for Volume (%s) to detach from Instance: %s",
vID, iID)
}
d.SetId("")
return nil
}
. As an alternative to the change made in this PR, this error handling could be omitted entirely making the methods more similar. Just a thought...

@stack72
Copy link
Contributor

stack72 commented Jul 25, 2016

Hi @Jonnymcc

Sorry it has taken so long to get to this PR. This looks good to me :)

The test results are as follows:

% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSENI_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSENI_ -timeout 120m
=== RUN   TestAccAWSENI_importBasic
--- PASS: TestAccAWSENI_importBasic (67.51s)
=== RUN   TestAccAWSENI_basic
--- PASS: TestAccAWSENI_basic (66.50s)
=== RUN   TestAccAWSENI_updatedDescription
--- PASS: TestAccAWSENI_updatedDescription (111.93s)
=== RUN   TestAccAWSENI_attached
--- PASS: TestAccAWSENI_attached (293.74s)
=== RUN   TestAccAWSENI_ignoreExternalAttachment
--- PASS: TestAccAWSENI_ignoreExternalAttachment (254.76s)
=== RUN   TestAccAWSENI_sourceDestCheck
--- PASS: TestAccAWSENI_sourceDestCheck (52.17s)
=== RUN   TestAccAWSENI_computedIPs
--- PASS: TestAccAWSENI_computedIPs (51.74s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    898.380s

Paul

@stack72 stack72 merged commit 3c702f2 into hashicorp:master Jul 25, 2016
@ghost
Copy link

ghost commented Apr 24, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants