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

resource/aws_glue_catalog_database: Prevent error when deleted outside Terraform #5141

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion aws/resource_aws_glue_catalog_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func resourceAwsGlueCatalogDatabaseRead(d *schema.ResourceData, meta interface{}
if isAWSErr(err, glue.ErrCodeEntityNotFoundException, "") {
log.Printf("[WARN] Glue Catalog Database (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

return fmt.Errorf("Error reading Glue Catalog Database: %s", err.Error())
Expand Down Expand Up @@ -187,7 +188,13 @@ func resourceAwsGlueCatalogDatabaseExists(d *schema.ResourceData, meta interface
}

_, err = glueconn.GetDatabase(input)
return err == nil, err
if err != nil {
if isAWSErr(err, glue.ErrCodeEntityNotFoundException, "") {
return false, nil
}
return false, err
}
return true, nil
}

func readAwsGlueCatalogID(id string) (catalogID string, name string, err error) {
Expand Down
35 changes: 35 additions & 0 deletions aws/resource_aws_glue_catalog_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,41 @@ func TestAccAWSGlueCatalogDatabase_full(t *testing.T) {
})
}

func TestAccAWSGlueCatalogDatabase_recreates(t *testing.T) {
resourceName := "aws_glue_catalog_database.test"
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGlueDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: testAccGlueCatalogDatabase_basic(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckGlueCatalogDatabaseExists(resourceName),
),
},
{
// Simulate deleting the database outside Terraform
PreConfig: func() {
conn := testAccProvider.Meta().(*AWSClient).glueconn
input := &glue.DeleteDatabaseInput{
Name: aws.String(fmt.Sprintf("my_test_catalog_database_%d", rInt)),
}
_, err := conn.DeleteDatabase(input)
if err != nil {
t.Fatalf("error deleting Glue Catalog Database: %s", err)
}
},
Config: testAccGlueCatalogDatabase_basic(rInt),
ExpectNonEmptyPlan: true,
PlanOnly: true,
},
},
})
}

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

Expand Down