Skip to content

Commit

Permalink
Merge pull request hashicorp#1551 from terraform-providers/b-eip-disa…
Browse files Browse the repository at this point in the history
…ppears

r/aws_eip: Remove from state on deletion
  • Loading branch information
radeksimko authored Sep 1, 2017
2 parents 412b8f1 + ec121d5 commit eccff9d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
if ok && (awsErr.Code() == "InvalidAllocationID.NotFound" ||
awsErr.Code() == "InvalidAddress.NotFound") {
log.Printf("[WARN] EIP not found, removing from state: %s", req)
d.SetId("")
return nil
}
return err
Expand Down
38 changes: 38 additions & 0 deletions aws/resource_aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,44 @@ func TestAccAWSEIP_classic_disassociate(t *testing.T) {
})
}

func TestAccAWSEIP_disappears(t *testing.T) {
var conf ec2.Address

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEIPDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEIPConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEIPExists("aws_eip.bar", &conf),
testAccCheckAWSEIPDisappears(&conf),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckAWSEIPDisappears(v *ec2.Address) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_eip" {
continue
}

_, err := conn.ReleaseAddress(&ec2.ReleaseAddressInput{
AllocationId: aws.String(rs.Primary.ID),
})
return err
}
return nil
}
}

func testAccCheckAWSEIPDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn

Expand Down

0 comments on commit eccff9d

Please sign in to comment.