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

Fix to not return err when instance is already terminated #6978

Conversation

teraken0509
Copy link
Contributor

Fixes #445 (?)

Changes proposed in this pull request:

  • Add error handling for instance delete step
  • Add test for disappears resource
  • Split waiting delete method.

Output from acceptance testing:

$  make testacc TESTARGS='-run=TestAccAWSInstance_disappears'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSInstance_disappears -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSInstance_disappears
=== PAUSE TestAccAWSInstance_disappears
=== CONT  TestAccAWSInstance_disappears
--- PASS: TestAccAWSInstance_disappears (137.68s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	137.738s
...

@ghost ghost added size/S Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Dec 25, 2018
@bflad bflad added the bug Addresses a defect in current functionality. label Jan 8, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this @kterada0509! 🚀

--- PASS: TestAccAWSInstance_ipv6AddressCountAndSingleAddressCausesError (10.41s)
--- PASS: TestAccAWSInstance_importInDefaultVpcBySgId (83.98s)
--- PASS: TestAccAWSInstance_ipv6_supportAddressCountWithIpv4 (83.91s)
--- PASS: TestAccAWSInstance_rootInstanceStore (95.05s)
--- PASS: TestAccAWSInstance_ipv6_supportAddressCount (95.52s)
--- PASS: TestAccAWSInstance_importInEc2Classic (97.14s)
--- PASS: TestAccAWSInstance_importBasic (103.57s)
--- PASS: TestAccAWSInstance_basic (119.88s)
--- PASS: TestAccAWSInstance_sourceDestCheck (141.98s)
--- PASS: TestAccAWSInstance_userDataBase64 (157.33s)
--- PASS: TestAccAWSInstance_noAMIEphemeralDevices (164.08s)
--- PASS: TestAccAWSInstance_volumeTags (78.86s)
--- PASS: TestAccAWSInstance_placementGroup (177.02s)
--- PASS: TestAccAWSInstance_GP2IopsDevice (180.10s)
--- PASS: TestAccAWSInstance_GP2WithIopsValue (182.39s)
--- PASS: TestAccAWSInstance_blockDevices (183.38s)
--- PASS: TestAccAWSInstance_NetworkInstanceVPCSecurityGroupIDs (101.60s)
--- PASS: TestAccAWSInstance_vpc (192.70s)
--- PASS: TestAccAWSInstance_volumeTagsComputed (98.65s)
--- PASS: TestAccAWSInstance_importInDefaultVpcBySgName (197.24s)
--- PASS: TestAccAWSInstance_tags (119.61s)
--- PASS: TestAccAWSInstance_NetworkInstanceSecurityGroups (207.21s)
--- PASS: TestAccAWSInstance_privateIP (89.49s)
--- PASS: TestAccAWSInstance_instanceProfileChange (120.07s)
--- PASS: TestAccAWSInstance_NetworkInstanceRemovingAllSecurityGroups (212.10s)
--- PASS: TestAccAWSInstance_associatePublicIPAndPrivateIP (92.06s)
--- PASS: TestAccAWSInstance_disableApiTermination (246.64s)
--- PASS: TestAccAWSInstance_primaryNetworkInterface (80.86s)
--- PASS: TestAccAWSInstance_associatePublic_defaultPrivate (71.12s)
--- PASS: TestAccAWSInstance_addSecondaryInterface (84.16s)
--- PASS: TestAccAWSInstance_multipleRegions (271.50s)
--- PASS: TestAccAWSInstance_associatePublic_overridePublic (80.18s)
--- PASS: TestAccAWSInstance_associatePublic_overridePrivate (86.44s)
--- PASS: TestAccAWSInstance_creditSpecification_unspecifiedDefaultsToStandard (70.11s)
--- PASS: TestAccAWSInstance_withIamInstanceProfile (239.13s)
--- PASS: TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable (76.34s)
--- PASS: TestAccAWSInstance_rootBlockDeviceMismatch (181.37s)
--- PASS: TestAccAWSInstance_keyPairCheck (193.72s)
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits (91.89s)
--- PASS: TestAccAWSInstance_creditSpecification_updateCpuCredits (89.21s)
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits (108.92s)
--- PASS: TestAccAWSInstance_associatePublic_defaultPublic (180.19s)
--- PASS: TestAccAWSInstance_getPasswordData_trueToFalse (154.62s)
--- PASS: TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits (88.29s)
--- PASS: TestAccAWSInstance_associatePublic_explicitPublic (192.06s)
--- PASS: TestAccAWSInstance_getPasswordData_falseToTrue (175.79s)
--- PASS: TestAccAWSInstance_creditSpecificationT3_updateCpuCredits (94.46s)
--- PASS: TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck (224.59s)
--- PASS: TestAccAWSInstance_forceNewAndTagsDrift (239.48s)
--- PASS: TestAccAWSInstance_associatePublic_explicitPrivate (234.79s)
--- PASS: TestAccAWSInstance_UserData_EmptyStringToUnspecified (115.72s)
--- PASS: TestAccAWSInstance_UserData_UnspecifiedToEmptyString (115.44s)
--- PASS: TestAccAWSInstance_addSecurityGroupNetworkInterface (287.64s)
--- PASS: TestAccAWSInstance_changeInstanceType (332.98s)
--- PASS: TestAccAWSInstance_disappears (206.87s)
--- PASS: TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited (295.97s)
--- PASS: TestAccAWSInstance_creditSpecificationT3_standardCpuCredits (289.25s)
--- PASS: TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint (357.40s)
--- PASS: TestAccAWSInstance_creditSpecification_standardCpuCredits_t2Tot3Taint (509.95s)

@@ -1925,9 +1925,16 @@ func awsTerminateInstance(conn *ec2.EC2, id string, timeout time.Duration) error
InstanceIds: []*string{aws.String(id)},
}
if _, err := conn.TerminateInstances(req); err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidInstanceID.NotFound" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We have a helper function for these, e.g. isAWSErr(err, "InvalidInstanceID.NotFound", ""), definitely not a blocker though

@@ -1942,6 +1942,27 @@ func TestAccAWSInstance_creditSpecification_unlimitedCpuCredits_t2Tot3Taint(t *t
})
}

func TestAccAWSInstance_disappears(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@bflad bflad added this to the v1.55.0 milestone Jan 8, 2019
@bflad bflad merged commit cd9a0e5 into hashicorp:master Jan 8, 2019
bflad added a commit that referenced this pull request Jan 8, 2019
@bflad
Copy link
Contributor

bflad commented Jan 10, 2019

This has been released in version 1.55.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@teraken0509 teraken0509 deleted the feature/fix-instance-resource-destroy-not-found-error branch March 5, 2020 14:06
@ghost
Copy link

ghost commented Mar 5, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. size/S Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform should clean up state when deposed instances already terminated
2 participants