Skip to content

Commit

Permalink
Merge pull request #15948 from DrFaust92/r/glue_classifier_csv
Browse files Browse the repository at this point in the history
r/glue_classifier - `quote_symbol` fix optional
  • Loading branch information
breathingdust authored Nov 4, 2020
2 parents 038751f + 4c24a2a commit ea4b429
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 26 deletions.
37 changes: 14 additions & 23 deletions aws/resource_aws_glue_classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func resourceAwsGlueClassifier() *schema.Resource {
"contains_header": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateHeaderOptions(),
ValidateFunc: validation.StringInSlice(glue.CsvHeaderOption_Values(), false),
},
"delimiter": {
Type: schema.TypeString,
Expand All @@ -77,6 +77,7 @@ func resourceAwsGlueClassifier() *schema.Resource {
"disable_value_trimming": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"header": {
Type: schema.TypeList,
Expand Down Expand Up @@ -285,14 +286,6 @@ func resourceAwsGlueClassifierDelete(d *schema.ResourceData, meta interface{}) e
return nil
}

func validateHeaderOptions() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
"UNKNOWN",
"PRESENT",
"ABSENT",
}, true)
}

func deleteGlueClassifier(conn *glue.Glue, name string) error {
input := &glue.DeleteClassifierInput{
Name: aws.String(name),
Expand All @@ -316,15 +309,14 @@ func expandGlueCsvClassifierCreate(name string, m map[string]interface{}) *glue.
Delimiter: aws.String(m["delimiter"].(string)),
DisableValueTrimming: aws.Bool(m["disable_value_trimming"].(bool)),
Name: aws.String(name),
QuoteSymbol: aws.String(m["quote_symbol"].(string)),
}

if v, ok := m["header"]; ok {
header := make([]string, len(v.([]interface{})))
for i, item := range v.([]interface{}) {
header[i] = fmt.Sprint(item)
}
csvClassifier.Header = aws.StringSlice(header)
if v, ok := m["quote_symbol"].(string); ok && v != "" {
csvClassifier.QuoteSymbol = aws.String(v)
}

if v, ok := m["header"].([]interface{}); ok {
csvClassifier.Header = expandStringList(v)
}

return csvClassifier
Expand All @@ -337,15 +329,14 @@ func expandGlueCsvClassifierUpdate(name string, m map[string]interface{}) *glue.
Delimiter: aws.String(m["delimiter"].(string)),
DisableValueTrimming: aws.Bool(m["disable_value_trimming"].(bool)),
Name: aws.String(name),
QuoteSymbol: aws.String(m["quote_symbol"].(string)),
}

if v, ok := m["header"]; ok {
header := make([]string, len(v.([]interface{})))
for i, item := range v.([]interface{}) {
header[i] = fmt.Sprint(item)
}
csvClassifier.Header = aws.StringSlice(header)
if v, ok := m["quote_symbol"].(string); ok && v != "" {
csvClassifier.QuoteSymbol = aws.String(v)
}

if v, ok := m["header"].([]interface{}); ok {
csvClassifier.Header = expandStringList(v)
}

return csvClassifier
Expand Down
78 changes: 75 additions & 3 deletions aws/resource_aws_glue_classifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestAccAWSGlueClassifier_CsvClassifier(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.disable_value_trimming", "false"),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.header.0", "header_column1"),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.header.1", "header_column2"),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.quote_symbol", "\""),
resource.TestCheckResourceAttr(resourceName, "grok_classifier.#", "0"),
resource.TestCheckResourceAttr(resourceName, "json_classifier.#", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
Expand All @@ -107,7 +106,6 @@ func TestAccAWSGlueClassifier_CsvClassifier(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.disable_value_trimming", "false"),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.header.0", "header_column1"),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.header.1", "header_column2"),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.quote_symbol", "\""),
resource.TestCheckResourceAttr(resourceName, "grok_classifier.#", "0"),
resource.TestCheckResourceAttr(resourceName, "json_classifier.#", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
Expand All @@ -123,6 +121,42 @@ func TestAccAWSGlueClassifier_CsvClassifier(t *testing.T) {
})
}

func TestAccAWSGlueClassifier_CsvClassifier_quoteSymbol(t *testing.T) {
var classifier glue.Classifier

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_glue_classifier.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSGlueClassifierDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSGlueClassifierConfigCsvClassifierQuoteSymbol(rName, "\""),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueClassifierExists(resourceName, &classifier),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.#", "1"),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.quote_symbol", "\""),
),
},
{
Config: testAccAWSGlueClassifierConfigCsvClassifierQuoteSymbol(rName, "'"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueClassifierExists(resourceName, &classifier),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.#", "1"),
resource.TestCheckResourceAttr(resourceName, "csv_classifier.0.quote_symbol", "'"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSGlueClassifier_GrokClassifier(t *testing.T) {
var classifier glue.Classifier

Expand Down Expand Up @@ -377,6 +411,29 @@ func TestAccAWSGlueClassifier_XmlClassifier(t *testing.T) {
})
}

func TestAccAWSGlueClassifier_disappears(t *testing.T) {
var classifier glue.Classifier

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_glue_classifier.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSGlueClassifierDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSGlueClassifierConfig_CsvClassifier(rName, false, "PRESENT", "|", false),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueClassifierExists(resourceName, &classifier),
testAccCheckResourceDisappears(testAccProvider, resourceAwsGlueClassifier(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckAWSGlueClassifierExists(resourceName string, classifier *glue.Classifier) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -447,12 +504,27 @@ resource "aws_glue_classifier" "test" {
delimiter = "%s"
disable_value_trimming = "%t"
header = ["header_column1", "header_column2"]
quote_symbol = "\""
}
}
`, rName, allowSingleColumn, containsHeader, delimiter, disableValueTrimming)
}

func testAccAWSGlueClassifierConfigCsvClassifierQuoteSymbol(rName, symbol string) string {
return fmt.Sprintf(`
resource "aws_glue_classifier" "test" {
name = %[1]q
csv_classifier {
allow_single_column = false
contains_header = "PRESENT"
delimiter = ","
header = ["header_column1", "header_column2"]
quote_symbol = %[2]q
}
}
`, rName, symbol)
}

func testAccAWSGlueClassifierConfig_GrokClassifier(rName, classification, grokPattern string) string {
return fmt.Sprintf(`
resource "aws_glue_classifier" "test" {
Expand Down

0 comments on commit ea4b429

Please sign in to comment.