Skip to content

Commit

Permalink
changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Apr 5, 2024
1 parent bd1ef58 commit 99653b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/resources/grant_ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ To transfer ownership of a pipe(s) **semi-automatically** you have to:
2. Create Terraform configuration with the `snowflake_grant_ownership` resource and perform ownership transfer with the `terraform apply`.
3. To resume the pipe(s) after ownership transfer use [PIPE_FORCE_RESUME system function](https://docs.snowflake.com/en/sql-reference/functions/system_pipe_force_resume).

## Granting ownership on tasks



## Granting ownership on external tables
Expand Down
41 changes: 27 additions & 14 deletions pkg/resources/grant_ownership_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ func TestAcc_GrantOwnership_TargetObjectRemovedOutsideTerraform(t *testing.T) {
},
{
PreConfig: func() {
grantOwnershipToTheCurrentRole(t, sdk.OwnershipGrantOn{
Object: &sdk.Object{
ObjectType: sdk.ObjectTypeDatabase,
Name: sdk.NewAccountObjectIdentifier(databaseName),
},
})
cleanupDatabase()
},
ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantOwnership/OnObject_Database_ToAccountRole_NoDatabaseResource"),
Expand Down Expand Up @@ -782,6 +788,7 @@ provider "snowflake" {
}
resource "snowflake_schema" "test" {
depends_on = [snowflake_role.test]
provider = snowflake.secondary
database = snowflake_database.test.name
name = "%s"
Expand Down Expand Up @@ -1091,24 +1098,30 @@ func createDatabase(t *testing.T, name string) func() {
assert.NoError(t, client.Databases.Create(ctx, roleId, new(sdk.CreateDatabaseOptions)))

return func() {
currentRole, err := client.ContextFunctions.CurrentRole(ctx)
assert.NoError(t, err)
err = client.Grants.GrantOwnership(ctx, sdk.OwnershipGrantOn{
Object: &sdk.Object{
ObjectType: sdk.ObjectTypeDatabase,
Name: roleId,
},
},
sdk.OwnershipGrantTo{
AccountRoleName: sdk.Pointer(sdk.NewAccountObjectIdentifier(currentRole)),
},
new(sdk.GrantOwnershipOptions),
)
assert.NoError(t, err)
assert.NoError(t, client.Databases.Drop(ctx, roleId, new(sdk.DropDatabaseOptions)))
}
}

func grantOwnershipToTheCurrentRole(t *testing.T, on sdk.OwnershipGrantOn) {
t.Helper()
client, err := sdk.NewDefaultClient()
assert.NoError(t, err)

ctx := context.Background()
currentRole, err := client.ContextFunctions.CurrentRole(ctx)
assert.NoError(t, err)

err = client.Grants.GrantOwnership(
ctx,
on,
sdk.OwnershipGrantTo{
AccountRoleName: sdk.Pointer(sdk.NewAccountObjectIdentifier(currentRole)),
},
new(sdk.GrantOwnershipOptions),
)
assert.NoError(t, err)
}

func getCurrentUser(t *testing.T) string {
t.Helper()
client, err := sdk.NewDefaultClient()
Expand Down
2 changes: 1 addition & 1 deletion templates/resources/grant_ownership.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To transfer ownership of a pipe(s) **semi-automatically** you have to:
2. Create Terraform configuration with the `snowflake_grant_ownership` resource and perform ownership transfer with the `terraform apply`.
3. To resume the pipe(s) after ownership transfer use [PIPE_FORCE_RESUME system function](https://docs.snowflake.com/en/sql-reference/functions/system_pipe_force_resume).

## Granting ownership on tasks
{{/*## Granting ownership on tasks*/}}
{{/* TODO: In next pr */}}

## Granting ownership on external tables
Expand Down

0 comments on commit 99653b6

Please sign in to comment.