Skip to content

Commit

Permalink
fix: grant privileges to share test terraform dependencies (#2473)
Browse files Browse the repository at this point in the history
Had to add dependencies between share and database, because sometimes
the tests are trying to drop the database before share, which is illegal
👮‍♂️
  • Loading branch information
sfc-gh-jcieslak authored Feb 12, 2024
1 parent a5f969c commit ede8d95
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 52 deletions.
10 changes: 10 additions & 0 deletions docs/resources/grant_privileges_to_share.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
##################################
Expand Down
6 changes: 6 additions & 0 deletions docs/resources/share.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
10 changes: 10 additions & 0 deletions examples/resources/snowflake_grant_privileges_to_share/resource.tf
Original file line number Diff line number Diff line change
@@ -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
##################################
Expand Down
6 changes: 6 additions & 0 deletions examples/resources/snowflake_share/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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" {
name = var.schema
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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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" {
name = var.schema
database = snowflake_database.test.name
}

resource "snowflake_share" "test" {
name = var.to_share
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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" {
name = var.schema
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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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" {
name = var.schema
database = snowflake_database.test.name
}

resource "snowflake_share" "test" {
name = var.to_share
}
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -16,7 +21,3 @@ resource "snowflake_table" "test" {
type = "NUMBER(38,0)"
}
}

resource "snowflake_share" "test" {
name = var.to_share
}
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down

0 comments on commit ede8d95

Please sign in to comment.