-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling compute pools privileges
References: #2717
- Loading branch information
1 parent
9888d49
commit 09f67b4
Showing
6 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TODO [SNOW-1790174]: change raw sqls to proper client | ||
type ComputePoolClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewComputePoolClient(context *TestClientContext, idsGenerator *IdsGenerator) *ComputePoolClient { | ||
return &ComputePoolClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *ComputePoolClient) client() *sdk.Client { | ||
return c.context.client | ||
} | ||
|
||
func (c *ComputePoolClient) CreateComputePool(t *testing.T) (sdk.AccountObjectIdentifier, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
id := c.ids.RandomAccountObjectIdentifier() | ||
_, err := c.client().ExecForTests(ctx, fmt.Sprintf(`CREATE COMPUTE POOL %s MIN_NODES = 1 MAX_NODES = 1 INSTANCE_FAMILY = CPU_X64_XS`, id.FullyQualifiedName())) | ||
require.NoError(t, err) | ||
return id, c.DropComputePoolFunc(t, id) | ||
} | ||
|
||
func (c *ComputePoolClient) DropComputePoolFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return func() { | ||
_, err := c.client().ExecForTests(ctx, fmt.Sprintf(`DROP COMPUTE POOL IF EXISTS %s`, id.FullyQualifiedName())) | ||
require.NoError(t, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
pkg/resources/testdata/TestAcc_GrantPrivilegesToAccountRole/OnAccountObject_gh2717/test.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "snowflake_grant_privileges_to_account_role" "test" { | ||
account_role_name = var.name | ||
privileges = var.privileges | ||
on_account_object { | ||
object_type = "COMPUTE POOL" | ||
object_name = var.compute_pool | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...sources/testdata/TestAcc_GrantPrivilegesToAccountRole/OnAccountObject_gh2717/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "name" { | ||
type = string | ||
} | ||
|
||
variable "compute_pool" { | ||
type = string | ||
} | ||
|
||
variable "privileges" { | ||
type = list(string) | ||
} |