Skip to content

Commit

Permalink
adjust returned types
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Feb 12, 2024
1 parent f6fc170 commit 3aeca80
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 52 deletions.
4 changes: 1 addition & 3 deletions docs/resources/user_password_policy_attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ resource "snowflake_user_password_policy_attachment" "ppa" {

### Required

- `password_policy_database` (String) Database name where the password policy is stored
- `password_policy_name` (String) Non-qualified name of the password policy
- `password_policy_schema` (String) Schema name where the password policy is stored
- `password_policy_name` (String) Fully qualified name of the password policy
- `user_name` (String) User name of the user you want to attach the password policy to

### Read-Only
Expand Down
13 changes: 7 additions & 6 deletions pkg/resources/user_password_policy_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ var userPasswordPolicyAttachmentSchema = map[string]*schema.Schema{
Description: "User name of the user you want to attach the password policy to",
},
"password_policy_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Fully qualified name of the password policy",
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Fully qualified name of the password policy",
ValidateDiagFunc: IsValidIdentifier[sdk.SchemaObjectIdentifier](),
},
}

Expand Down Expand Up @@ -95,8 +96,8 @@ func ReadUserPasswordPolicyAttachment(d *schema.ResourceData, meta any) error {
if err := d.Set(
"password_policy_name",
sdk.NewSchemaObjectIdentifier(
policyReferences[0].PolicyDb,
policyReferences[0].PolicySchema,
*policyReferences[0].PolicyDb,
*policyReferences[0].PolicySchema,
policyReferences[0].PolicyName,
).FullyQualifiedName()); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func testAccCheckUserPasswordPolicyAttachmentDestroy(s *terraform.State) error {
return nil
}

func userPasswordPolicyAttachmentConfig(userName, databaseName, schemaName, prefix string) string {
func userPasswordPolicyAttachmentConfig(userName, databaseName, schemaName, passwordPolicyName string) string {
return fmt.Sprintf(`
resource "snowflake_user" "user" {
name = "%s"
Expand All @@ -96,5 +96,5 @@ resource "snowflake_user_password_policy_attachment" "ppa" {
password_policy_name = "\"${snowflake_password_policy.pp.database}\".\"${snowflake_password_policy.pp.schema}\".\"${snowflake_password_policy.pp.name}\""
user_name = snowflake_user.user.name
}
`, userName, databaseName, schemaName, prefix)
`, userName, databaseName, schemaName, passwordPolicyName)
}
70 changes: 30 additions & 40 deletions pkg/sdk/policy_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,83 +38,73 @@ type policyReferenceFunctionArguments struct {
}

type PolicyReference struct {
PolicyDb string
PolicySchema string
PolicyDb *string
PolicySchema *string
PolicyName string
PolicyKind string
RefDatabaseName string
RefSchemaName string
RefDatabaseName *string
RefSchemaName *string
RefEntityName string
RefEntityDomain string
RefColumnName string
RefArgColumnNames string
TagDatabase string
TagSchema string
TagName string
RefColumnName *string
RefArgColumnNames *string
TagDatabase *string
TagSchema *string
TagName *string
PolicyStatus string
}

// TODO: Check types
type policyReferenceDBRow struct {
PolicyDb sql.NullString `db:"POLICY_DB"`
PolicySchema sql.NullString `db:"POLICY_SCHEMA"`
PolicyName sql.NullString `db:"POLICY_NAME"`
PolicyKind sql.NullString `db:"POLICY_KIND"`
PolicyName string `db:"POLICY_NAME"`
PolicyKind string `db:"POLICY_KIND"`
RefDatabaseName sql.NullString `db:"REF_DATABASE_NAME"`
RefSchemaName sql.NullString `db:"REF_SCHEMA_NAME"`
RefEntityName sql.NullString `db:"REF_ENTITY_NAME"`
RefEntityDomain sql.NullString `db:"REF_ENTITY_DOMAIN"`
RefEntityName string `db:"REF_ENTITY_NAME"`
RefEntityDomain string `db:"REF_ENTITY_DOMAIN"`
RefColumnName sql.NullString `db:"REF_COLUMN_NAME"`
RefArgColumnNames sql.NullString `db:"REF_ARG_COLUMN_NAMES"`
TagDatabase sql.NullString `db:"TAG_DATABASE"`
TagSchema sql.NullString `db:"TAG_SCHEMA"`
TagName sql.NullString `db:"TAG_NAME"`
PolicyStatus sql.NullString `db:"POLICY_STATUS"`
PolicyStatus string `db:"POLICY_STATUS"`
}

func (row policyReferenceDBRow) convert() *PolicyReference {
policyReference := PolicyReference{}
policyReference := PolicyReference{
PolicyName: row.PolicyName,
PolicyKind: row.PolicyKind,
RefEntityName: row.RefEntityName,
RefEntityDomain: row.RefEntityDomain,
PolicyStatus: row.PolicyStatus,
}
if row.PolicyDb.Valid {
policyReference.PolicyDb = row.PolicyDb.String
policyReference.PolicyDb = &row.PolicyDb.String
}
if row.PolicySchema.Valid {
policyReference.PolicySchema = row.PolicySchema.String
}
if row.PolicyName.Valid {
policyReference.PolicyName = row.PolicyName.String
}
if row.PolicyKind.Valid {
policyReference.PolicyKind = row.PolicyKind.String
policyReference.PolicySchema = &row.PolicySchema.String
}
if row.RefDatabaseName.Valid {
policyReference.RefDatabaseName = row.RefDatabaseName.String
policyReference.RefDatabaseName = &row.RefDatabaseName.String
}
if row.RefSchemaName.Valid {
policyReference.RefSchemaName = row.RefSchemaName.String
}
if row.RefEntityName.Valid {
policyReference.RefEntityName = row.RefEntityName.String
}
if row.RefEntityDomain.Valid {
policyReference.RefEntityDomain = row.RefEntityDomain.String
policyReference.RefSchemaName = &row.RefSchemaName.String
}
if row.RefColumnName.Valid {
policyReference.RefColumnName = row.RefColumnName.String
policyReference.RefColumnName = &row.RefColumnName.String
}
if row.RefArgColumnNames.Valid {
policyReference.RefArgColumnNames = row.RefArgColumnNames.String
policyReference.RefArgColumnNames = &row.RefArgColumnNames.String
}
if row.TagDatabase.Valid {
policyReference.TagDatabase = row.TagDatabase.String
policyReference.TagDatabase = &row.TagDatabase.String
}
if row.TagSchema.Valid {
policyReference.TagSchema = row.TagSchema.String
policyReference.TagSchema = &row.TagSchema.String
}
if row.TagName.Valid {
policyReference.TagName = row.TagName.String
}
if row.PolicyStatus.Valid {
policyReference.PolicyStatus = row.PolicyStatus.String
policyReference.TagName = &row.TagName.String
}
return &policyReference
}
3 changes: 2 additions & 1 deletion pkg/sdk/testint/policy_references_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package testint

import (
"testing"

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

func TestInt_PolicyReferences(t *testing.T) {
Expand Down

0 comments on commit 3aeca80

Please sign in to comment.