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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

b/Unsetting ser_de_info.name from aws_glue_catalog_table results in error #15127

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions aws/resource_aws_glue_catalog_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,19 +500,19 @@ 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)
}
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))
}

Expand Down
80 changes: 80 additions & 0 deletions aws/resource_aws_glue_catalog_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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" {
Expand Down