From ede8d9547ed5d4e6f2b39d8e41f1b09981d7d9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Cie=C5=9Blak?= Date: Mon, 12 Feb 2024 11:17:53 +0100 Subject: [PATCH] fix: grant privileges to share test terraform dependencies (#2473) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Had to add dependencies between share and database, because sometimes the tests are trying to drop the database before share, which is illegal 👮‍♂️ --- docs/resources/grant_privileges_to_share.md | 10 ++++++++++ docs/resources/share.md | 6 ++++++ .../snowflake_grant_privileges_to_share/resource.tf | 10 ++++++++++ examples/resources/snowflake_share/resource.tf | 6 ++++++ .../OnAllTablesInSchema/test.tf | 11 ++++++----- .../OnAllTablesInSchema_NoGrant/test.tf | 10 ++++++---- .../OnDatabase_NoGrant/test.tf | 9 +++++---- .../OnDatabase_NoPrivileges/test.tf | 9 +++++---- .../TestAcc_GrantPrivilegesToShare/OnSchema/test.tf | 11 ++++++----- .../OnSchema_NoGrant/test.tf | 10 ++++++---- .../TestAcc_GrantPrivilegesToShare/OnTable/test.tf | 11 ++++++----- .../OnTable_NoGrant/test.tf | 11 ++++++----- .../TestAcc_GrantPrivilegesToShare/OnTag/test.tf | 11 ++++++----- .../OnTag_NoGrant/test.tf | 11 ++++++----- .../TestAcc_GrantPrivilegesToShare/OnView/test.tf | 11 ++++++----- .../OnView_NoGrant/test.tf | 7 ++++++- 16 files changed, 102 insertions(+), 52 deletions(-) diff --git a/docs/resources/grant_privileges_to_share.md b/docs/resources/grant_privileges_to_share.md index 0beac830ba..a9e4c07377 100644 --- a/docs/resources/grant_privileges_to_share.md +++ b/docs/resources/grant_privileges_to_share.md @@ -15,6 +15,16 @@ description: |- ## Example Usage ```terraform +resource "snowflake_share" "example" { + name = "test" +} + +resource "snowflake_database" "example" { + # remember to define dependency between objects on a share, because shared objects have to be dropped before dropping share + depends_on = [snowflake_share.example] + name = "test" +} + ################################## ### on database ################################## diff --git a/docs/resources/share.md b/docs/resources/share.md index 9e1fd4f958..7951c87016 100644 --- a/docs/resources/share.md +++ b/docs/resources/share.md @@ -18,6 +18,12 @@ resource "snowflake_share" "test" { comment = "cool comment" accounts = ["organizationName.accountName"] } + +resource "snowflake_database" "example" { + # remember to define dependency between objects on a share, because shared objects have to be dropped before dropping share + depends_on = [snowflake_share.test] + name = "test" +} ``` diff --git a/examples/resources/snowflake_grant_privileges_to_share/resource.tf b/examples/resources/snowflake_grant_privileges_to_share/resource.tf index a213e6cc8f..1f1376e414 100644 --- a/examples/resources/snowflake_grant_privileges_to_share/resource.tf +++ b/examples/resources/snowflake_grant_privileges_to_share/resource.tf @@ -1,3 +1,13 @@ +resource "snowflake_share" "example" { + name = "test" +} + +resource "snowflake_database" "example" { + # remember to define dependency between objects on a share, because shared objects have to be dropped before dropping share + depends_on = [snowflake_share.example] + name = "test" +} + ################################## ### on database ################################## diff --git a/examples/resources/snowflake_share/resource.tf b/examples/resources/snowflake_share/resource.tf index bfd197e080..6857739721 100644 --- a/examples/resources/snowflake_share/resource.tf +++ b/examples/resources/snowflake_share/resource.tf @@ -3,3 +3,9 @@ resource "snowflake_share" "test" { comment = "cool comment" accounts = ["organizationName.accountName"] } + +resource "snowflake_database" "example" { + # remember to define dependency between objects on a share, because shared objects have to be dropped before dropping share + depends_on = [snowflake_share.test] + name = "test" +} diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnAllTablesInSchema/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnAllTablesInSchema/test.tf index 1805c18714..7793a9f2ee 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnAllTablesInSchema/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnAllTablesInSchema/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -7,10 +12,6 @@ resource "snowflake_schema" "test" { database = snowflake_database.test.name } -resource "snowflake_share" "test" { - name = var.to_share -} - resource "snowflake_grant_privileges_to_share" "test_setup" { to_share = snowflake_share.test.name privileges = ["USAGE"] diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnAllTablesInSchema_NoGrant/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnAllTablesInSchema_NoGrant/test.tf index beb3470c6a..1daed03174 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnAllTablesInSchema_NoGrant/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnAllTablesInSchema_NoGrant/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -7,6 +12,3 @@ resource "snowflake_schema" "test" { database = snowflake_database.test.name } -resource "snowflake_share" "test" { - name = var.to_share -} diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnDatabase_NoGrant/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnDatabase_NoGrant/test.tf index 50bdc08e8d..491a840a98 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnDatabase_NoGrant/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnDatabase_NoGrant/test.tf @@ -1,7 +1,8 @@ -resource "snowflake_database" "test" { - name = var.database -} - resource "snowflake_share" "test" { name = var.to_share } + +resource "snowflake_database" "test" { + depends_on = [snowflake_share.test] + name = var.database +} diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnDatabase_NoPrivileges/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnDatabase_NoPrivileges/test.tf index 6026bc53b1..7bff22cc4d 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnDatabase_NoPrivileges/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnDatabase_NoPrivileges/test.tf @@ -1,11 +1,12 @@ -resource "snowflake_database" "test" { - name = var.database -} - resource "snowflake_share" "test" { name = var.to_share } +resource "snowflake_database" "test" { + depends_on = [snowflake_share.test] + name = var.database +} + resource "snowflake_grant_privileges_to_share" "test" { to_share = snowflake_share.test.name on_database = snowflake_database.test.name diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnSchema/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnSchema/test.tf index 6fedcefe97..fb050ce39e 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnSchema/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnSchema/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -7,10 +12,6 @@ resource "snowflake_schema" "test" { database = snowflake_database.test.name } -resource "snowflake_share" "test" { - name = var.to_share -} - resource "snowflake_grant_privileges_to_share" "test_setup" { to_share = snowflake_share.test.name privileges = ["USAGE"] diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnSchema_NoGrant/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnSchema_NoGrant/test.tf index beb3470c6a..1daed03174 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnSchema_NoGrant/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnSchema_NoGrant/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -7,6 +12,3 @@ resource "snowflake_schema" "test" { database = snowflake_database.test.name } -resource "snowflake_share" "test" { - name = var.to_share -} diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTable/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTable/test.tf index 58e3beddbf..47e2188469 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTable/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTable/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -17,10 +22,6 @@ resource "snowflake_table" "test" { } } -resource "snowflake_share" "test" { - name = var.to_share -} - resource "snowflake_grant_privileges_to_share" "test_setup" { to_share = snowflake_share.test.name privileges = ["USAGE"] diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTable_NoGrant/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTable_NoGrant/test.tf index 9b65cdd148..9680c26a43 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTable_NoGrant/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTable_NoGrant/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -16,7 +21,3 @@ resource "snowflake_table" "test" { type = "NUMBER(38,0)" } } - -resource "snowflake_share" "test" { - name = var.to_share -} diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTag/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTag/test.tf index 728b944946..d711da7287 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTag/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTag/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -13,10 +18,6 @@ resource "snowflake_tag" "test" { schema = snowflake_schema.test.name } -resource "snowflake_share" "test" { - name = var.to_share -} - resource "snowflake_grant_privileges_to_share" "test_setup" { to_share = snowflake_share.test.name privileges = ["USAGE"] diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTag_NoGrant/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTag_NoGrant/test.tf index 58f711ee44..dc3b3e955d 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTag_NoGrant/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnTag_NoGrant/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -12,7 +17,3 @@ resource "snowflake_tag" "test" { database = snowflake_database.test.name schema = snowflake_schema.test.name } - -resource "snowflake_share" "test" { - name = var.to_share -} diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnView/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnView/test.tf index 5c504320f9..cd8a65737b 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnView/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnView/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" { @@ -25,10 +30,6 @@ resource "snowflake_view" "test" { statement = "select \"id\" from \"${snowflake_database.test.name}\".\"${snowflake_schema.test.name}\".\"${snowflake_table.test.name}\"" } -resource "snowflake_share" "test" { - name = var.to_share -} - resource "snowflake_grant_privileges_to_share" "test_setup" { to_share = snowflake_share.test.name privileges = ["USAGE"] diff --git a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnView_NoGrant/test.tf b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnView_NoGrant/test.tf index 91137560e5..bf70f5d448 100644 --- a/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnView_NoGrant/test.tf +++ b/pkg/resources/testdata/TestAcc_GrantPrivilegesToShare/OnView_NoGrant/test.tf @@ -1,5 +1,10 @@ +resource "snowflake_share" "test" { + name = var.to_share +} + resource "snowflake_database" "test" { - name = var.database + depends_on = [snowflake_share.test] + name = var.database } resource "snowflake_schema" "test" {