diff --git a/aws/resource_aws_glue_catalog_table.go b/aws/resource_aws_glue_catalog_table.go index 02fd66c7a6a..e803e449255 100644 --- a/aws/resource_aws_glue_catalog_table.go +++ b/aws/resource_aws_glue_catalog_table.go @@ -503,11 +503,11 @@ func expandGlueSerDeInfo(l []interface{}) *glue.SerDeInfo { s := l[0].(map[string]interface{}) serDeInfo := &glue.SerDeInfo{} - if v, ok := s["name"]; ok { + if v := s["name"]; len(v.(string)) > 0 { serDeInfo.Name = aws.String(v.(string)) } - if v, ok := s["parameters"]; ok { + if v := s["parameters"]; len(v.(map[string]interface{})) > 0 { paramsMap := map[string]string{} for key, value := range v.(map[string]interface{}) { paramsMap[key] = value.(string) @@ -515,7 +515,7 @@ func expandGlueSerDeInfo(l []interface{}) *glue.SerDeInfo { serDeInfo.Parameters = aws.StringMap(paramsMap) } - if v, ok := s["serialization_library"]; ok { + if v := s["serialization_library"]; len(v.(string)) > 0 { serDeInfo.SerializationLibrary = aws.String(v.(string)) } diff --git a/aws/resource_aws_glue_catalog_table_test.go b/aws/resource_aws_glue_catalog_table_test.go index dda1414f2b7..41d17cab073 100644 --- a/aws/resource_aws_glue_catalog_table_test.go +++ b/aws/resource_aws_glue_catalog_table_test.go @@ -367,6 +367,45 @@ func TestAccAWSGlueCatalogTable_StorageDescriptor_SerDeInfo_EmptyConfigurationBl }) } +func TestAccAWSGlueCatalogTable_StorageDescriptor_SerDeInfo_UpdateValues(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_glue_catalog_table.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckGlueTableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccGlueCatalogTableConfigStorageDescriptorSerDeInfo(rName), + Destroy: false, + Check: resource.ComposeTestCheckFunc( + testAccCheckGlueCatalogTableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "database_name", rName), + resource.TestCheckResourceAttr(resourceName, "storage_descriptor.0.ser_de_info.0.name", "ser_de_name"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccGlueCatalogTableConfigStorageDescriptorSerDeInfoUpdate(rName), + Destroy: false, + Check: resource.ComposeTestCheckFunc( + testAccCheckGlueCatalogTableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "database_name", rName), + resource.TestCheckResourceAttr(resourceName, "storage_descriptor.0.ser_de_info.0.parameters.param1", "param_val_1"), + resource.TestCheckResourceAttr(resourceName, "storage_descriptor.0.ser_de_info.0.serialization_library", "org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe"), + ), + }, + }, + }) +} + // Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/11784 func TestAccAWSGlueCatalogTable_StorageDescriptor_SkewedInfo_EmptyConfigurationBlock(t *testing.T) { rName := acctest.RandomWithPrefix("tf-acc-test") @@ -641,6 +680,47 @@ resource "aws_glue_catalog_table" "test" { `, rName) } +func testAccGlueCatalogTableConfigStorageDescriptorSerDeInfo(rName string) string { + return fmt.Sprintf(` +resource "aws_glue_catalog_database" "test" { + name = %[1]q +} + +resource "aws_glue_catalog_table" "test" { + database_name = aws_glue_catalog_database.test.name + name = %[1]q + + storage_descriptor { + ser_de_info { + name = "ser_de_name" + } + } +} +`, rName) +} + +func testAccGlueCatalogTableConfigStorageDescriptorSerDeInfoUpdate(rName string) string { + return fmt.Sprintf(` +resource "aws_glue_catalog_database" "test" { + name = %[1]q +} + +resource "aws_glue_catalog_table" "test" { + database_name = aws_glue_catalog_database.test.name + name = %[1]q + + storage_descriptor { + ser_de_info { + parameters = { + param1 = "param_val_1" + } + serialization_library = "org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe" + } + } +} +`, rName) +} + func testAccGlueCatalogTableConfigStorageDescriptorSkewedInfoEmptyConfigurationBlock(rName string) string { return fmt.Sprintf(` resource "aws_glue_catalog_database" "test" {