Skip to content

Commit

Permalink
Merge pull request #15127 from nikhil-goenka/aws_glue_catalog_table-S…
Browse files Browse the repository at this point in the history
…erDeInfo

b/Unsetting ser_de_info.name from aws_glue_catalog_table results in error
  • Loading branch information
breathingdust authored Oct 21, 2020
2 parents 40d9cb7 + 0003aa0 commit c12e9a5
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
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 @@ -503,19 +503,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

0 comments on commit c12e9a5

Please sign in to comment.