Skip to content

Commit

Permalink
fix: remove share feature from stage because it isn't supported (#918)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurochan committed Mar 15, 2022
1 parent adbb52e commit 7229387
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
3 changes: 1 addition & 2 deletions docs/resources/stage_grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ resource snowflake_stage_grant grant {
### Optional

- **id** (String) The ID of this resource.
- **on_future** (Boolean) When this is set to true and a schema_name is provided, apply this grant on all future stages in the given schema. When this is true and no schema_name is provided apply this grant on all future stages in the given database. The stage_name and shares fields must be unset in order to use on_future.
- **on_future** (Boolean) When this is set to true and a schema_name is provided, apply this grant on all future stages in the given schema. When this is true and no schema_name is provided apply this grant on all future stages in the given database. The stage_name field must be unset in order to use on_future.
- **privilege** (String) The privilege to grant on the stage.
- **roles** (Set of String) Grants privilege to these roles.
- **shares** (Set of String) Grants privilege to these shares (only valid if on_future is false).
- **stage_name** (String) The name of the stage on which to grant privilege (only valid if on_future is false).
- **with_grant_option** (Boolean) When this is set to true, allows the recipient role to grant the privileges to other roles.

Expand Down
11 changes: 2 additions & 9 deletions pkg/resources/stage_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,13 @@ var stageGrantSchema = map[string]*schema.Schema{
Description: "Grants privilege to these roles.",
ForceNew: true,
},
"shares": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "Grants privilege to these shares (only valid if on_future is false).",
ForceNew: true,
},
"on_future": {
Type: schema.TypeBool,
Optional: true,
Description: "When this is set to true and a schema_name is provided, apply this grant on all future stages in the given schema. When this is true and no schema_name is provided apply this grant on all future stages in the given database. The stage_name and shares fields must be unset in order to use on_future.",
Description: "When this is set to true and a schema_name is provided, apply this grant on all future stages in the given schema. When this is true and no schema_name is provided apply this grant on all future stages in the given database. The stage_name field must be unset in order to use on_future.",
Default: false,
ForceNew: true,
ConflictsWith: []string{"stage_name", "shares"},
ConflictsWith: []string{"stage_name"},
},
"with_grant_option": {
Type: schema.TypeBool,
Expand Down
13 changes: 0 additions & 13 deletions pkg/resources/stage_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func TestStageGrantCreate(t *testing.T) {
"database_name": "test-db",
"privilege": test_priv,
"roles": []interface{}{"test-role-1", "test-role-2"},
"shares": []interface{}{"test-share-1", "test-share-2"},
"with_grant_option": true,
}
d := schema.TestResourceDataRaw(t, resources.StageGrant().Resource.Schema, in)
Expand All @@ -39,8 +38,6 @@ func TestStageGrantCreate(t *testing.T) {
WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(fmt.Sprintf(`^GRANT %s ON STAGE "test-db"."test-schema"."test-stage" TO ROLE "test-role-1" WITH GRANT OPTION$`, test_priv)).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec(fmt.Sprintf(`^GRANT %s ON STAGE "test-db"."test-schema"."test-stage" TO ROLE "test-role-2" WITH GRANT OPTION$`, test_priv)).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec(fmt.Sprintf(`^GRANT %s ON STAGE "test-db"."test-schema"."test-stage" TO SHARE "test-share-1" WITH GRANT OPTION$`, test_priv)).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec(fmt.Sprintf(`^GRANT %s ON STAGE "test-db"."test-schema"."test-stage" TO SHARE "test-share-2" WITH GRANT OPTION$`, test_priv)).WillReturnResult(sqlmock.NewResult(1, 1))
expectReadStageGrant(mock, test_priv)
err := resources.CreateStageGrant(d, db)
r.NoError(err)
Expand All @@ -57,7 +54,6 @@ func TestStageGrantRead(t *testing.T) {
"database_name": "test-db",
"privilege": "USAGE",
"roles": []interface{}{},
"shares": []interface{}{},
"with_grant_option": false,
})

Expand All @@ -73,11 +69,6 @@ func TestStageGrantRead(t *testing.T) {
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
}

func expectReadStageGrant(mock sqlmock.Sqlmock, test_priv string) {
Expand All @@ -87,10 +78,6 @@ func expectReadStageGrant(mock sqlmock.Sqlmock, test_priv string) {
time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), test_priv, "STAGE", "test-stage", "ROLE", "test-role-1", false, "bob",
).AddRow(
time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), test_priv, "STAGE", "test-stage", "ROLE", "test-role-2", false, "bob",
).AddRow(
time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), test_priv, "STAGE", "test-stage", "SHARE", "test-share-1", false, "bob",
).AddRow(
time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), test_priv, "STAGE", "test-stage", "SHARE", "test-share-2", false, "bob",
)
mock.ExpectQuery(`^SHOW GRANTS ON STAGE "test-db"."test-schema"."test-stage"$`).WillReturnRows(rows)
}
Expand Down

0 comments on commit 7229387

Please sign in to comment.