From 45293161b0a44ff60681a5b10967b2c7c70360be Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 30 Oct 2020 23:53:06 +0200 Subject: [PATCH 1/4] quote symbol really optional --- aws/resource_aws_glue_classifier.go | 29 +++++---- aws/resource_aws_glue_classifier_test.go | 78 +++++++++++++++++++++++- 2 files changed, 89 insertions(+), 18 deletions(-) diff --git a/aws/resource_aws_glue_classifier.go b/aws/resource_aws_glue_classifier.go index d89c4a99fc7..327f50c7be9 100644 --- a/aws/resource_aws_glue_classifier.go +++ b/aws/resource_aws_glue_classifier.go @@ -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, @@ -77,6 +77,7 @@ func resourceAwsGlueClassifier() *schema.Resource { "disable_value_trimming": { Type: schema.TypeBool, Optional: true, + Default: true, }, "header": { Type: schema.TypeList, @@ -316,15 +317,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 @@ -337,15 +337,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 diff --git a/aws/resource_aws_glue_classifier_test.go b/aws/resource_aws_glue_classifier_test.go index 2a6fcc09f79..afe1732d9e8 100644 --- a/aws/resource_aws_glue_classifier_test.go +++ b/aws/resource_aws_glue_classifier_test.go @@ -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), @@ -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), @@ -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 @@ -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] @@ -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" { From fa22c2d57f5de04aca42fd42ca4bc2d19481f693 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 31 Oct 2020 00:03:14 +0200 Subject: [PATCH 2/4] fmt --- aws/resource_aws_glue_classifier_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_glue_classifier_test.go b/aws/resource_aws_glue_classifier_test.go index afe1732d9e8..e8c2254858f 100644 --- a/aws/resource_aws_glue_classifier_test.go +++ b/aws/resource_aws_glue_classifier_test.go @@ -519,7 +519,7 @@ resource "aws_glue_classifier" "test" { contains_header = "PRESENT" delimiter = "," header = ["header_column1", "header_column2"] - quote_symbol = %[2]q + quote_symbol = %[2]q } } `, rName, symbol) From 4c672aca5813ad88bae812743f0cab56495009c7 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 31 Oct 2020 09:48:46 +0200 Subject: [PATCH 3/4] fmt --- aws/resource_aws_glue_classifier_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_glue_classifier_test.go b/aws/resource_aws_glue_classifier_test.go index e8c2254858f..34e88dab803 100644 --- a/aws/resource_aws_glue_classifier_test.go +++ b/aws/resource_aws_glue_classifier_test.go @@ -518,7 +518,7 @@ resource "aws_glue_classifier" "test" { allow_single_column = false contains_header = "PRESENT" delimiter = "," - header = ["header_column1", "header_column2"] + header = ["header_column1", "header_column2"] quote_symbol = %[2]q } } From 4c24a2af021ff1180cbc3f286655955a23d9df1f Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 31 Oct 2020 10:35:14 +0200 Subject: [PATCH 4/4] remove validation func --- aws/resource_aws_glue_classifier.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/aws/resource_aws_glue_classifier.go b/aws/resource_aws_glue_classifier.go index 327f50c7be9..fb83988e634 100644 --- a/aws/resource_aws_glue_classifier.go +++ b/aws/resource_aws_glue_classifier.go @@ -286,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),