Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Jan 3, 2024
1 parent 631db5a commit 6767e9d
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/resources/grant_privileges_to_database_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ where:
- grant_type - enum
- grant_data - enum data

It has varying number of parts, depending on <grant_type>. All the possible types are:
It has varying number of parts, depending on grant_type. All the possible types are:

### OnDatabase
`terraform import "<database_role_name>|<with_grant_option>|<always_apply>|<privileges>|OnDatabase|<database_name>"`
Expand Down
7 changes: 4 additions & 3 deletions pkg/resources/grant_privileges_to_database_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"database/sql"
"fmt"
"slices"
"strings"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"slices"
"strings"
)

// TODO: Imported privileges (after second account will be added)
Expand Down Expand Up @@ -645,7 +646,7 @@ func ReadGrantPrivilegesToDatabaseRole(ctx context.Context, d *schema.ResourceDa
if id.WithGrantOption == grant.GrantOption && id.DatabaseRoleName.Name() == grant.GranteeName.Name() {
// Future grants do not have grantedBy, only current grants do.
// If grantedby is an empty string, it means terraform could not have created the grant
if (opts.Future == nil || *opts.Future == false) && grant.GrantedBy.Name() == "" {
if (opts.Future == nil || !*opts.Future) && grant.GrantedBy.Name() == "" {
continue
}
// grant_on is for future grants, granted_on is for current grants.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"database/sql"
"fmt"
"regexp"
"testing"

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
"regexp"
"testing"
)

func TestAcc_GrantPrivilegesToDatabaseRole_OnDatabase(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/resources/grant_privileges_to_database_role_identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package resources

import (
"fmt"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/helpers"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"strconv"
"strings"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/helpers"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

type DatabaseRoleGrantKind string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package resources

import (
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/stretchr/testify/assert"
"testing"
)

func TestParseGrantPrivilegesToDatabaseRoleId(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
all_privileges = var.all_privileges
on_database = "\"${var.database}\""
always_apply = var.always_apply
all_privileges = var.all_privileges
on_database = "\"${var.database}\""
always_apply = var.always_apply
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
privileges = var.privileges
with_grant_option = var.with_grant_option
privileges = var.privileges
with_grant_option = var.with_grant_option

on_schema {
all_schemas_in_database = "\"${var.database}\""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
privileges = var.privileges
on_database = "\"${var.database}\""
with_grant_option = var.with_grant_option
privileges = var.privileges
on_database = "\"${var.database}\""
with_grant_option = var.with_grant_option
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
privileges = var.privileges
with_grant_option = var.with_grant_option
privileges = var.privileges
with_grant_option = var.with_grant_option

on_schema {
future_schemas_in_database = "\"${var.database}\""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
privileges = var.privileges
with_grant_option = var.with_grant_option
privileges = var.privileges
with_grant_option = var.with_grant_option

on_schema {
schema_name = "\"${var.database}\".\"${var.schema}\""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
privileges = var.privileges
with_grant_option = var.with_grant_option
privileges = var.privileges
with_grant_option = var.with_grant_option

on_schema_object {
all {
object_type_plural = "TABLES"
in_database = "\"${var.database}\""
in_database = "\"${var.database}\""
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
privileges = var.privileges
with_grant_option = var.with_grant_option
privileges = var.privileges
with_grant_option = var.with_grant_option

on_schema_object {
future {
object_type_plural = "TABLES"
in_database = "\"${var.database}\""
in_database = "\"${var.database}\""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ resource "snowflake_table" "test" {
}

resource "snowflake_grant_privileges_to_database_role" "test" {
depends_on = [snowflake_table.test]
depends_on = [snowflake_table.test]
database_role_name = "\"${var.database}\".\"${var.name}\""
privileges = var.privileges
with_grant_option = var.with_grant_option
privileges = var.privileges
with_grant_option = var.with_grant_option

on_schema_object {
object_type = "TABLE"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
all_privileges = var.all_privileges
on_database = "\"${var.database}\""
all_privileges = var.all_privileges
on_database = "\"${var.database}\""
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "snowflake_grant_privileges_to_database_role" "test" {
database_role_name = "\"${var.database}\".\"${var.name}\""
privileges = var.privileges
on_database = "\"${var.database}\""
privileges = var.privileges
on_database = "\"${var.database}\""
}

0 comments on commit 6767e9d

Please sign in to comment.