Skip to content

Commit

Permalink
Revert "provider/aws: Fix dependency violation with subnets and secur…
Browse files Browse the repository at this point in the history
…ity groups"

This reverts commit 3d80057.

Rationale: There is no guarantee that waiting will resolve the
DependencyViolation. It's possible, perhaps likely, that the thing
preventing the subnet deletion was created by some other means -- by
another user, by a dynamic application, in another manifest, or that it
was created by this manifest but for some other reason failed to be
deleted.

In these cases, the retry behavior makes the user wait 5 minutes only to
receive the misleading error:

Error deleting subnet: timeout while waiting for state to become
'destroyed'

The obvious response to this is to try again, which yields another 5
minutes of waiting.

The previous behavior was to fail quickly with an error which exactly
described the problem. While this is mildly annoying, it's at least
apparent what is happening.

The situation the original commit was intended to address could be more
elegantly addressed by:

  - running Terraform a second time, or
  - explicitly declaring dependencies via the `depends_on` attribute.
  • Loading branch information
Phil Frost committed Apr 9, 2015
1 parent 36e364a commit 1bab291
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions builtin/providers/aws/resource_aws_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,38 +159,17 @@ func resourceAwsSubnetDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2SDKconn

log.Printf("[INFO] Deleting subnet: %s", d.Id())
req := &ec2.DeleteSubnetInput{
SubnetID: aws.String(d.Id()),
}

wait := resource.StateChangeConf{
Pending: []string{"pending"},
Target: "destroyed",
Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
_, err := conn.DeleteSubnet(req)
if err != nil {
if apiErr, ok := err.(aws.APIError); ok {
if apiErr.Code == "DependencyViolation" {
// There is some pending operation, so just retry
// in a bit.
return 42, "pending", nil
}

if apiErr.Code == "InvalidSubnetID.NotFound" {
return 42, "destroyed", nil
}
}

return 42, "failure", err
}
_, err := conn.DeleteSubnet(&ec2.DeleteSubnetInput{
SubnetID: aws.String(d.Id()),
})

return 42, "destroyed", nil
},
}
if err != nil {
ec2err, ok := err.(aws.APIError)
if ok && ec2err.Code == "InvalidSubnetID.NotFound" {
return nil
}

if _, err := wait.WaitForState(); err != nil {
return fmt.Errorf("Error deleting subnet: %s", err)
}

Expand Down

0 comments on commit 1bab291

Please sign in to comment.