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: Properly return error when missing colon during import #5123

Merged
merged 1 commit into from
Jul 9, 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
31 changes: 23 additions & 8 deletions aws/resource_aws_glue_catalog_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ func resourceAwsGlueCatalogDatabaseCreate(d *schema.ResourceData, meta interface
func resourceAwsGlueCatalogDatabaseUpdate(d *schema.ResourceData, meta interface{}) error {
glueconn := meta.(*AWSClient).glueconn

catalogID, name := readAwsGlueCatalogID(d.Id())
catalogID, name, err := readAwsGlueCatalogID(d.Id())
if err != nil {
return err
}

dbUpdateInput := &glue.UpdateDatabaseInput{
CatalogId: aws.String(catalogID),
Expand Down Expand Up @@ -117,7 +120,10 @@ func resourceAwsGlueCatalogDatabaseUpdate(d *schema.ResourceData, meta interface
func resourceAwsGlueCatalogDatabaseRead(d *schema.ResourceData, meta interface{}) error {
glueconn := meta.(*AWSClient).glueconn

catalogID, name := readAwsGlueCatalogID(d.Id())
catalogID, name, err := readAwsGlueCatalogID(d.Id())
if err != nil {
return err
}

input := &glue.GetDatabaseInput{
CatalogId: aws.String(catalogID),
Expand Down Expand Up @@ -153,10 +159,13 @@ func resourceAwsGlueCatalogDatabaseRead(d *schema.ResourceData, meta interface{}

func resourceAwsGlueCatalogDatabaseDelete(d *schema.ResourceData, meta interface{}) error {
glueconn := meta.(*AWSClient).glueconn
catalogID, name := readAwsGlueCatalogID(d.Id())
catalogID, name, err := readAwsGlueCatalogID(d.Id())
if err != nil {
return err
}

log.Printf("[DEBUG] Glue Catalog Database: %s:%s", catalogID, name)
_, err := glueconn.DeleteDatabase(&glue.DeleteDatabaseInput{
_, err = glueconn.DeleteDatabase(&glue.DeleteDatabaseInput{
Name: aws.String(name),
})
if err != nil {
Expand All @@ -167,20 +176,26 @@ func resourceAwsGlueCatalogDatabaseDelete(d *schema.ResourceData, meta interface

func resourceAwsGlueCatalogDatabaseExists(d *schema.ResourceData, meta interface{}) (bool, error) {
glueconn := meta.(*AWSClient).glueconn
catalogID, name := readAwsGlueCatalogID(d.Id())
catalogID, name, err := readAwsGlueCatalogID(d.Id())
if err != nil {
return false, err
}

input := &glue.GetDatabaseInput{
CatalogId: aws.String(catalogID),
Name: aws.String(name),
}

_, err := glueconn.GetDatabase(input)
_, err = glueconn.GetDatabase(input)
return err == nil, err
}

func readAwsGlueCatalogID(id string) (catalogID string, name string) {
func readAwsGlueCatalogID(id string) (catalogID string, name string, err error) {
idParts := strings.Split(id, ":")
return idParts[0], idParts[1]
if len(idParts) != 2 {
return "", "", fmt.Errorf("Unexpected format of ID (%q), expected CATALOG-ID:DATABASE-NAME", id)
}
return idParts[0], idParts[1], nil
}

func createAwsGlueCatalogID(d *schema.ResourceData, accountid string) (catalogID string) {
Expand Down
10 changes: 8 additions & 2 deletions aws/resource_aws_glue_catalog_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ func testAccCheckGlueDatabaseDestroy(s *terraform.State) error {
continue
}

catalogId, dbName := readAwsGlueCatalogID(rs.Primary.ID)
catalogId, dbName, err := readAwsGlueCatalogID(rs.Primary.ID)
if err != nil {
return err
}

input := &glue.GetDatabaseInput{
CatalogId: aws.String(catalogId),
Expand Down Expand Up @@ -174,7 +177,10 @@ func testAccCheckGlueCatalogDatabaseExists(name string) resource.TestCheckFunc {
return fmt.Errorf("No ID is set")
}

catalogId, dbName := readAwsGlueCatalogID(rs.Primary.ID)
catalogId, dbName, err := readAwsGlueCatalogID(rs.Primary.ID)
if err != nil {
return err
}

glueconn := testAccProvider.Meta().(*AWSClient).glueconn
out, err := glueconn.GetDatabase(&glue.GetDatabaseInput{
Expand Down