Remove aws_vpc_dhcp_options if not found. (#13610)
This commit is contained in:
parent
b348cff246
commit
5c3438e394
|
@ -147,7 +147,18 @@ func resourceAwsVpcDhcpOptionsRead(d *schema.ResourceData, meta interface{}) err
|
||||||
|
|
||||||
resp, err := conn.DescribeDhcpOptions(req)
|
resp, err := conn.DescribeDhcpOptions(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error retrieving DHCP Options: %s", err)
|
ec2err, ok := err.(awserr.Error)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Error retrieving DHCP Options: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if ec2err.Code() == "InvalidDhcpOptionID.NotFound" {
|
||||||
|
log.Printf("[WARN] DHCP Options (%s) not found, removing from state", d.Id())
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Error retrieving DHCP Options: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(resp.DhcpOptions) == 0 {
|
if len(resp.DhcpOptions) == 0 {
|
||||||
|
|
|
@ -36,6 +36,26 @@ func TestAccAWSDHCPOptions_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSDHCPOptions_deleteOptions(t *testing.T) {
|
||||||
|
var d ec2.DhcpOptions
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckDHCPOptionsDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccDHCPOptionsConfig,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckDHCPOptionsExists("aws_vpc_dhcp_options.foo", &d),
|
||||||
|
testAccCheckDHCPOptionsDelete("aws_vpc_dhcp_options.foo"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckDHCPOptionsDestroy(s *terraform.State) error {
|
func testAccCheckDHCPOptionsDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
|
||||||
|
@ -104,6 +124,26 @@ func testAccCheckDHCPOptionsExists(n string, d *ec2.DhcpOptions) resource.TestCh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckDHCPOptionsDelete(n string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rs.Primary.ID == "" {
|
||||||
|
return fmt.Errorf("No ID is set")
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||||
|
_, err := conn.DeleteDhcpOptions(&ec2.DeleteDhcpOptionsInput{
|
||||||
|
DhcpOptionsId: aws.String(rs.Primary.ID),
|
||||||
|
})
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const testAccDHCPOptionsConfig = `
|
const testAccDHCPOptionsConfig = `
|
||||||
resource "aws_vpc_dhcp_options" "foo" {
|
resource "aws_vpc_dhcp_options" "foo" {
|
||||||
domain_name = "service.consul"
|
domain_name = "service.consul"
|
||||||
|
|
Loading…
Reference in New Issue