Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add resource snowflake_user_password_policy_attachment (#2162) #2307

Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4ea1227
fix: passwordPolicy is of type identifier, not parameter
raulbonet Dec 24, 2023
a8673c7
feat: snowflake_user_password_policy_attachment . Initial working ver…
raulbonet Dec 24, 2023
3f7caa9
fix: fix syntax for TestAlterUser regarding password policies
raulbonet Dec 24, 2023
dac0fb6
feat: basic acceptance test working
raulbonet Dec 24, 2023
74bcfbf
refactor: passwordPolicy is now imported directly as a SchemaObject
raulbonet Dec 24, 2023
33fa5b1
fix: all parameters are now set in the state
raulbonet Dec 24, 2023
d7a6bf8
fix: Create() now ends with returning the Read()
raulbonet Dec 24, 2023
ff00696
fix: d.Set() now is checked for errors
raulbonet Dec 24, 2023
ca77bcd
fix: for now, do not implement the read function
raulbonet Dec 25, 2023
423a631
fix: change to FullyQualifiedName() to avoid detection of changes
raulbonet Dec 25, 2023
f574c07
fix: tests now do not rely on an existing user
raulbonet Dec 25, 2023
e83c3b4
docs: documentation for the new resource generated
raulbonet Jan 3, 2024
3ab1ad6
feat: read() method implemented for Policy References
raulbonet Jan 14, 2024
7b2daa4
fix: terraform now does not detect changes due to the format in which…
raulbonet Jan 14, 2024
5194f54
feat: acceptance tests for Update(). Delete still not working
raulbonet Jan 14, 2024
ceea700
feat: acceptance tests for Delete()
raulbonet Jan 15, 2024
9db2bc5
fix: Update() method in PasswordPolicy should return Read()
raulbonet Jan 21, 2024
37c3b85
refactor: we stopped using the fully qualified name of the passwordPo…
raulbonet Jan 21, 2024
3ce49c9
feat: tests working for Read(), Update() and Import
raulbonet Jan 21, 2024
3ae77ce
refactor: the sdk for PasswordPolicies resemble more the one for Stre…
raulbonet Jan 21, 2024
38d9e7f
fix: user_name now can be also lowercase
raulbonet Jan 21, 2024
bba2aa3
fix: checkDelete working again
raulbonet Jan 21, 2024
748bb6d
refactor: cleanup comments
raulbonet Jan 21, 2024
a0a930b
feat: implement validate()
raulbonet Jan 21, 2024
d9e01eb
refactor: getForEntityPolicyReferenceOptions is better designed now
raulbonet Jan 21, 2024
678ca9b
docs: run make dev-setup && make docs
raulbonet Jan 21, 2024
fc0c309
refactor: cleanup
raulbonet Jan 21, 2024
bd1babc
refactor: go formatting
raulbonet Jan 21, 2024
7bd734c
Merge branch 'main' into feature/2162/user-attach-password-policy
raulbonet Jan 21, 2024
98cc325
fix: docs for the schema now up-to-date
raulbonet Feb 3, 2024
61dcfbd
refactor: Read() function does not have to set IDs
raulbonet Feb 5, 2024
e223416
fix: comment in id should not contain "roles"
raulbonet Feb 5, 2024
69b49cc
refactor: passwordPolicy instantiated without the need of auxiliary v…
raulbonet Feb 5, 2024
d09bab9
fix: destroy needs to set id to null
raulbonet Feb 5, 2024
f9e8978
refactor: rename destroy function check
raulbonet Feb 5, 2024
bb8eb03
fix: RefEntityName and RefEntityDomain are not optional fields
raulbonet Feb 5, 2024
65bfcca
refactor: some fields do not need to be set to true explicitly
raulbonet Feb 5, 2024
3a5fad4
fix: passwordPolicy in UserSet should not be optional
raulbonet Feb 5, 2024
160a4c7
refactor: refEntityName is better an ObjectIdentifier than a string
raulbonet Feb 5, 2024
c0d761a
docs: provided examples
raulbonet Feb 5, 2024
e245c98
refactor: id parsing in the importer
raulbonet Feb 6, 2024
da6d012
feature: some unit tests
raulbonet Feb 7, 2024
7cf198f
feature: validation is now more specific
raulbonet Feb 7, 2024
5f5a965
feature: added missing arguments validation tests
raulbonet Feb 7, 2024
40810d0
feature: added tests for "Account" entity
raulbonet Feb 7, 2024
5a12da8
fix: wrong description
raulbonet Feb 7, 2024
9715d2a
feat: added tests for integration, tag and view
raulbonet Feb 7, 2024
25e6a2c
Merge branch 'main' into feature/2162/user-attach-password-policy
sfc-gh-asawicki Feb 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: id parsing in the importer
raulbonet committed Feb 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit e245c9847186e8a4c9108b2f014732d58e50e0f0
32 changes: 8 additions & 24 deletions pkg/resources/user_password_policy_attachment.go
Original file line number Diff line number Diff line change
@@ -49,29 +49,7 @@ func UserPasswordPolicyAttachment() *schema.Resource {
Schema: userPasswordPolicyAttachmentSchema,

Importer: &schema.ResourceImporter{
StateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), helpers.IDDelimiter)
if len(parts) != 4 {
return nil, fmt.Errorf("id should be in the format 'database|schema|password_policy|user_name', but I got '%s'", d.Id())
}
passwordPolicyDatabase := sdk.NewAccountIdentifierFromFullyQualifiedName(parts[0])
passwordPolicySchema := sdk.NewAccountIdentifierFromFullyQualifiedName(parts[1])
passwordPolicyName := sdk.NewAccountIdentifierFromFullyQualifiedName(parts[2])
userName := sdk.NewAccountObjectIdentifierFromFullyQualifiedName(parts[3])
if err := d.Set("password_policy_database", passwordPolicyDatabase.Name()); err != nil {
return nil, err
}
if err := d.Set("password_policy_schema", passwordPolicySchema.Name()); err != nil {
return nil, err
}
if err := d.Set("password_policy_name", passwordPolicyName.Name()); err != nil {
return nil, err
}
if err := d.Set("user_name", userName.Name()); err != nil {
return nil, err
}
return []*schema.ResourceData{d}, nil
},
StateContext: schema.ImportStatePassthroughContext,
},
}
}
@@ -102,10 +80,16 @@ func CreateUserPasswordPolicyAttachment(d *schema.ResourceData, meta interface{}
}

func ReadUserPasswordPolicyAttachment(d *schema.ResourceData, meta interface{}) error {
parts := strings.Split(d.Id(), helpers.IDDelimiter)
if len(parts) != 4 {
// Note: this exception handling is particularly useful when importing
return fmt.Errorf("id should be in the format 'database|schema|password_policy|user_name', but I got '%s'", d.Id())
}
// Note: there is no alphanumeric id for an attachment, so we retrieve the password policies attached to a certain user.
userName := sdk.NewAccountObjectIdentifierFromFullyQualifiedName(parts[3])
db := meta.(*sql.DB)
client := sdk.NewClientFromDB(db)
ctx := context.Background()
userName := sdk.NewAccountObjectIdentifierFromFullyQualifiedName(d.Get("user_name").(string))
policyReferences, err := client.PolicyReferences.GetForEntity(ctx, &sdk.GetForEntityPolicyReferenceRequest{
// Note: I cannot insert both single and double quotes in the SDK, so for now I need to do this
RefEntityName: userName.FullyQualifiedName(),