From b73af77386979581ed0d65d0d6c778dde5f53f58 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 10 Jun 2021 01:42:34 +0300 Subject: [PATCH 1/2] set location uri to computed --- aws/resource_aws_glue_catalog_database.go | 1 + ...resource_aws_glue_catalog_database_test.go | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/aws/resource_aws_glue_catalog_database.go b/aws/resource_aws_glue_catalog_database.go index 060cf932734..156c6d039b1 100644 --- a/aws/resource_aws_glue_catalog_database.go +++ b/aws/resource_aws_glue_catalog_database.go @@ -51,6 +51,7 @@ func resourceAwsGlueCatalogDatabase() *schema.Resource { "location_uri": { Type: schema.TypeString, Optional: true, + Computed: true, }, "parameters": { Type: schema.TypeMap, diff --git a/aws/resource_aws_glue_catalog_database_test.go b/aws/resource_aws_glue_catalog_database_test.go index 541520e6fee..1c1869658b1 100644 --- a/aws/resource_aws_glue_catalog_database_test.go +++ b/aws/resource_aws_glue_catalog_database_test.go @@ -141,6 +141,17 @@ func TestAccAWSGlueCatalogDatabase_targetDatabase(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccGlueCatalogDatabaseConfigTargetDatabaseWithLocation(rName), + Destroy: false, + Check: resource.ComposeTestCheckFunc( + testAccCheckGlueCatalogDatabaseExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "target_database.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "target_database.0.catalog_id", "aws_glue_catalog_database.test2", "catalog_id"), + resource.TestCheckResourceAttrPair(resourceName, "target_database.0.database_name", "aws_glue_catalog_database.test2", "name"), + resource.TestCheckResourceAttrPair(resourceName, "location_uri", "aws_glue_catalog_database.test2", "location_uri"), + ), + }, }, }) } @@ -238,6 +249,24 @@ resource "aws_glue_catalog_database" "test2" { `, rName) } +func testAccGlueCatalogDatabaseConfigTargetDatabaseWithLocation(rName string) string { + return fmt.Sprintf(` +resource "aws_glue_catalog_database" "test" { + name = %[1]q + + target_database { + catalog_id = aws_glue_catalog_database.test2.catalog_id + database_name = aws_glue_catalog_database.test2.name + } +} + +resource "aws_glue_catalog_database" "test2" { + name = "%[1]s-2" + location_uri = "my-location" +} +`, rName) +} + func testAccCheckGlueCatalogDatabaseExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] From 30befcde003cf0411bcef5aa8ddb981663e4ebd2 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 10 Jun 2021 01:45:59 +0300 Subject: [PATCH 2/2] changelog --- .changelog/19743.txt | 3 +++ aws/resource_aws_glue_catalog_database_test.go | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .changelog/19743.txt diff --git a/.changelog/19743.txt b/.changelog/19743.txt new file mode 100644 index 00000000000..0a392951498 --- /dev/null +++ b/.changelog/19743.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_glue_catalog_database: Set `location_uri` as compute to prevent drift when `target_table` has `location_uri` set. +``` \ No newline at end of file diff --git a/aws/resource_aws_glue_catalog_database_test.go b/aws/resource_aws_glue_catalog_database_test.go index 1c1869658b1..07b8b7883a4 100644 --- a/aws/resource_aws_glue_catalog_database_test.go +++ b/aws/resource_aws_glue_catalog_database_test.go @@ -149,7 +149,6 @@ func TestAccAWSGlueCatalogDatabase_targetDatabase(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "target_database.#", "1"), resource.TestCheckResourceAttrPair(resourceName, "target_database.0.catalog_id", "aws_glue_catalog_database.test2", "catalog_id"), resource.TestCheckResourceAttrPair(resourceName, "target_database.0.database_name", "aws_glue_catalog_database.test2", "name"), - resource.TestCheckResourceAttrPair(resourceName, "location_uri", "aws_glue_catalog_database.test2", "location_uri"), ), }, },