From 8eb2c9525bc59eb33e865676d79edcc4f0049e09 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 23 Aug 2020 21:27:02 +0300 Subject: [PATCH 1/2] allow removing schedule --- aws/resource_aws_glue_crawler.go | 27 ++++++++++++--------------- aws/resource_aws_glue_crawler_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/aws/resource_aws_glue_crawler.go b/aws/resource_aws_glue_crawler.go index f49e51777f7..fc416850d1e 100644 --- a/aws/resource_aws_glue_crawler.go +++ b/aws/resource_aws_glue_crawler.go @@ -81,23 +81,16 @@ func resourceAwsGlueCrawler() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "delete_behavior": { - Type: schema.TypeString, - Optional: true, - Default: glue.DeleteBehaviorDeprecateInDatabase, - ValidateFunc: validation.StringInSlice([]string{ - glue.DeleteBehaviorDeleteFromDatabase, - glue.DeleteBehaviorDeprecateInDatabase, - glue.DeleteBehaviorLog, - }, false), + Type: schema.TypeString, + Optional: true, + Default: glue.DeleteBehaviorDeprecateInDatabase, + ValidateFunc: validation.StringInSlice(glue.DeleteBehavior_Values(), false), }, "update_behavior": { - Type: schema.TypeString, - Optional: true, - Default: glue.UpdateBehaviorUpdateInDatabase, - ValidateFunc: validation.StringInSlice([]string{ - glue.UpdateBehaviorLog, - glue.UpdateBehaviorUpdateInDatabase, - }, false), + Type: schema.TypeString, + Optional: true, + Default: glue.UpdateBehaviorUpdateInDatabase, + ValidateFunc: validation.StringInSlice(glue.UpdateBehavior_Values(), false), }, }, }, @@ -291,9 +284,13 @@ func updateCrawlerInput(crawlerName string, d *schema.ResourceData) (*glue.Updat if description, ok := d.GetOk("description"); ok { crawlerInput.Description = aws.String(description.(string)) } + if schedule, ok := d.GetOk("schedule"); ok { crawlerInput.Schedule = aws.String(schedule.(string)) + } else { + crawlerInput.Schedule = aws.String("") } + if classifiers, ok := d.GetOk("classifiers"); ok { crawlerInput.Classifiers = expandStringList(classifiers.([]interface{})) } diff --git a/aws/resource_aws_glue_crawler_test.go b/aws/resource_aws_glue_crawler_test.go index ff835979e86..a2ffb2e3637 100644 --- a/aws/resource_aws_glue_crawler_test.go +++ b/aws/resource_aws_glue_crawler_test.go @@ -834,6 +834,13 @@ func TestAccAWSGlueCrawler_Schedule(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccGlueCrawlerBasicConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSGlueCrawlerExists(resourceName, &crawler), + resource.TestCheckResourceAttr(resourceName, "schedule", ""), + ), + }, }, }) } @@ -1675,6 +1682,26 @@ EOF `, rName) } +func testAccGlueCrawlerBasicConfig(rName string) string { + return testAccGlueCrawlerConfig_Base(rName) + fmt.Sprintf(` +resource "aws_glue_catalog_database" "test" { + name = %[1]q +} + +resource "aws_glue_crawler" "test" { + depends_on = [aws_iam_role_policy_attachment.test-AWSGlueServiceRole] + + database_name = aws_glue_catalog_database.test.name + name = %[1]q + role = aws_iam_role.test.name + + s3_target { + path = "s3://bucket-name" + } +} +`, rName) +} + func testAccGlueCrawlerConfig_Schedule(rName, schedule string) string { return testAccGlueCrawlerConfig_Base(rName) + fmt.Sprintf(` resource "aws_glue_catalog_database" "test" { From 3f20019a959350e3b1d58385b3b7f81fd78e063f Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sun, 23 Aug 2020 21:31:43 +0300 Subject: [PATCH 2/2] refactor disappears test --- aws/resource_aws_glue_crawler_test.go | 40 ++------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/aws/resource_aws_glue_crawler_test.go b/aws/resource_aws_glue_crawler_test.go index a2ffb2e3637..5370a3fc582 100644 --- a/aws/resource_aws_glue_crawler_test.go +++ b/aws/resource_aws_glue_crawler_test.go @@ -578,7 +578,7 @@ func TestAccAWSGlueCrawler_CatalogTarget_Multiple(t *testing.T) { }) } -func TestAccAWSGlueCrawler_recreates(t *testing.T) { +func TestAccAWSGlueCrawler_disappears(t *testing.T) { var crawler glue.Crawler rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_glue_crawler.test" @@ -592,23 +592,9 @@ func TestAccAWSGlueCrawler_recreates(t *testing.T) { Config: testAccGlueCrawlerConfig_S3Target(rName, "s3://bucket1"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSGlueCrawlerExists(resourceName, &crawler), + testAccCheckResourceDisappears(testAccProvider, resourceAwsGlueCrawler(), resourceName), ), - }, - { - // Simulate deleting the crawler outside Terraform - PreConfig: func() { - conn := testAccProvider.Meta().(*AWSClient).glueconn - input := &glue.DeleteCrawlerInput{ - Name: aws.String(rName), - } - _, err := conn.DeleteCrawler(input) - if err != nil { - t.Fatalf("error deleting Glue Crawler: %s", err) - } - }, - Config: testAccGlueCrawlerConfig_S3Target(rName, "s3://bucket1"), ExpectNonEmptyPlan: true, - PlanOnly: true, }, }, }) @@ -835,7 +821,7 @@ func TestAccAWSGlueCrawler_Schedule(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccGlueCrawlerBasicConfig(rName), + Config: testAccGlueCrawlerConfig_S3Target(rName, "s3://bucket-name"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSGlueCrawlerExists(resourceName, &crawler), resource.TestCheckResourceAttr(resourceName, "schedule", ""), @@ -1682,26 +1668,6 @@ EOF `, rName) } -func testAccGlueCrawlerBasicConfig(rName string) string { - return testAccGlueCrawlerConfig_Base(rName) + fmt.Sprintf(` -resource "aws_glue_catalog_database" "test" { - name = %[1]q -} - -resource "aws_glue_crawler" "test" { - depends_on = [aws_iam_role_policy_attachment.test-AWSGlueServiceRole] - - database_name = aws_glue_catalog_database.test.name - name = %[1]q - role = aws_iam_role.test.name - - s3_target { - path = "s3://bucket-name" - } -} -`, rName) -} - func testAccGlueCrawlerConfig_Schedule(rName, schedule string) string { return testAccGlueCrawlerConfig_Base(rName) + fmt.Sprintf(` resource "aws_glue_catalog_database" "test" {