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 service user and legacy service user resources #3119

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
64081d4
add service user and legacy service user resources starts here
sfc-gh-asawicki Oct 7, 2024
63d50d7
Add TODOs for tests
sfc-gh-asawicki Oct 7, 2024
ada8c6b
Add user type to SDK
sfc-gh-asawicki Oct 7, 2024
5ae4a0f
Test creation of service and legacy service users
sfc-gh-asawicki Oct 7, 2024
f0932cf
Check setting all parameters on all types of user
sfc-gh-asawicki Oct 7, 2024
b90f35f
Test service user creation with all object properties
sfc-gh-asawicki Oct 7, 2024
c222844
Test legacy service user creation with all object properties
sfc-gh-asawicki Oct 7, 2024
98c0742
Test service user incompatible fields
sfc-gh-asawicki Oct 7, 2024
224f024
Check set and unset behavior for service and legacy service users
sfc-gh-asawicki Oct 7, 2024
6b0ce7d
USe user type from the SDK
sfc-gh-asawicki Oct 7, 2024
58c286d
Remove TODO (tested in previous commits)
sfc-gh-asawicki Oct 7, 2024
0e48e89
Introduce service user resource
sfc-gh-asawicki Oct 7, 2024
076b934
Add TODOs
sfc-gh-asawicki Oct 7, 2024
38a6b34
Introduce legacy service user resource
sfc-gh-asawicki Oct 7, 2024
3766e59
Change the docs for different user types
sfc-gh-asawicki Oct 8, 2024
c2bda5c
Extract custom diffs
sfc-gh-asawicki Oct 8, 2024
05423ea
Parametrize create and import user functions in resource
sfc-gh-asawicki Oct 8, 2024
e1cef28
Parametrize update user function in resource
sfc-gh-asawicki Oct 8, 2024
88349b3
Parametrize read user function in resource
sfc-gh-asawicki Oct 8, 2024
0fb2ba2
Parametrize external changes for different types of users
sfc-gh-asawicki Oct 8, 2024
979a9ea
Fix TestAcc_User_issue2970
sfc-gh-asawicki Oct 8, 2024
720b6ce
Generate model and resource assertions for servicy and legacy service…
sfc-gh-asawicki Oct 8, 2024
4b3fb2a
Add basic service user resource acceptance tests
sfc-gh-asawicki Oct 8, 2024
707be44
Add basic legacy service user resource acceptance tests
sfc-gh-asawicki Oct 8, 2024
bddbefd
Add TODOs
sfc-gh-asawicki Oct 8, 2024
87cbcd3
Add tests for not allowed attributes
sfc-gh-asawicki Oct 8, 2024
de3e577
Add tests for users datasource and different user types
sfc-gh-asawicki Oct 8, 2024
a7d4d8f
Add the migration guide
sfc-gh-asawicki Oct 8, 2024
994d896
Check the docs
sfc-gh-asawicki Oct 8, 2024
c7aca44
Run pre-push
sfc-gh-asawicki Oct 8, 2024
7c3737b
Fix sweepers
sfc-gh-asawicki Oct 8, 2024
53051af
Merge branch 'main' into add-service-user-and-legacy-service-user-res…
sfc-gh-asawicki Oct 9, 2024
3a1ff98
Fix after review
sfc-gh-asawicki Oct 9, 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
30 changes: 30 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ across different versions.
> [!TIP]
> We highly recommend upgrading the versions one by one instead of bulk upgrades.

## v0.96.0 ➞ v0.97.0

### new snowflake_service_user and snowflake_legacy_service_user resources

Release v0.95.0 introduced reworked `snowflake_user` resource. As [noted](#note-user-types), the new `SERVICE` and `LEGACY_SERVICE` user types were not supported.

This release introduces two new resources to handle these new user types: `snowflake_service_user` and `snowflake_legacy_service_user`.

Both resources have schemas almost identical to the `snowflake_user` resource with the following exceptions:
- `snowflake_service_user` does not contain the following fields (because they are not supported for the user of type `SERVICE` in Snowflake):
- `password`
- `first_name`
- `middle_name`
- `last_name`
- `must_change_password`
- `mins_to_bypass_mfa`
- `disable_mfa`
- `snowflake_legacy_service_user` does not contain the following fields (because they are not supported for the user of type `LEGACY_SERVICE` in Snowflake):
- `first_name`
- `middle_name`
- `last_name`
- `mins_to_bypass_mfa`
- `disable_mfa`

`snowflake_users` datasource was adjusted to handle different user types and `type` field was added to the `describe_output`.

If you used to manage service or legacy service users through `snowflake_user` resource (e.g. using `lifecycle.ignore_changes`) or `snowflake_unsafe_execute`, please migrate to the new resources following [our guidelines on resource migration](docs/technical-documentation/resource_migration.md).
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved

Connected issues: [#2951](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2951)

## v0.95.0 ➞ v0.96.0

### snowflake_masking_policies data source changes
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Read-Only:
- `rsa_public_key_fp` (String)
- `snowflake_lock` (Boolean)
- `snowflake_support` (Boolean)
- `type` (String)


<a id="nestedobjatt--users--parameters"></a>
Expand Down
939 changes: 939 additions & 0 deletions docs/resources/legacy_service_user.md

Large diffs are not rendered by default.

934 changes: 934 additions & 0 deletions docs/resources/service_user.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: |-

-> **Note** Attaching user policies will be handled in the following versions of the provider which may still affect this resource.

-> **Note** `service` and `legacy_service` user types are currently not supported. They will be supported in the following versions as separate resources (namely `snowflake_service_user` and `snowflake_legacy_service_user`).
-> **Note** Other two user types are handled in separate resources: `snowflake_service_user` for user type `service` and `snowflake_legacy_service_user` for user type `legacy_service`.

-> **Note** External changes to `days_to_expiry`, `mins_to_unlock`, and `mins_to_bypass_mfa` are not currently handled by the provider (because the value changes continuously on Snowflake side after setting it).

Expand Down
1 change: 1 addition & 0 deletions examples/resources/snowflake_legacy_service_user/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import snowflake_legacy_service_user.example userName
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions examples/resources/snowflake_legacy_service_user/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "snowflake_legacy_service_user" "user" {
name = "Snowflake Legacy Service User"
login_name = "legacy_service_user"
comment = "A legacy service user of snowflake."
password = "secret"
disabled = false
display_name = "Snowflake Legacy Service User"
email = "[email protected]"

default_warehouse = "warehouse"
default_secondary_roles = "ALL"
default_role = "role1"

rsa_public_key = "..."
rsa_public_key_2 = "..."

must_change_password = true
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we create basic and complete version of resource configurations like for other resources?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for all user types

1 change: 1 addition & 0 deletions examples/resources/snowflake_service_user/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import snowflake_service_user.example userName
15 changes: 15 additions & 0 deletions examples/resources/snowflake_service_user/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "snowflake_service_user" "service_user" {
name = "Snowflake Service User"
login_name = "service_user"
comment = "A service user of snowflake."
disabled = false
display_name = "Snowflake Service User"
email = "[email protected]"

default_warehouse = "warehouse"
default_secondary_roles = "ALL"
default_role = "role1"

rsa_public_key = "..."
rsa_public_key_2 = "..."
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ var allResourceSchemaDefs = []ResourceSchemaDef{
name: "User",
schema: resources.User().Schema,
},
{
name: "ServiceUser",
schema: resources.ServiceUser().Schema,
},
{
name: "LegacyServiceUser",
schema: resources.LegacyServiceUser().Schema,
},
{
name: "View",
schema: resources.View().Schema,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package resourceassert

import (
"strconv"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

func (u *LegacyServiceUserResourceAssert) HasDisabled(expected bool) *LegacyServiceUserResourceAssert {
u.AddAssertion(assert.ValueSet("disabled", strconv.FormatBool(expected)))
return u
}

func (u *LegacyServiceUserResourceAssert) HasMustChangePassword(expected bool) *LegacyServiceUserResourceAssert {
u.AddAssertion(assert.ValueSet("must_change_password", strconv.FormatBool(expected)))
return u
}

func (u *LegacyServiceUserResourceAssert) HasDefaultSecondaryRolesOption(expected sdk.SecondaryRolesOption) *LegacyServiceUserResourceAssert {
return u.HasDefaultSecondaryRolesOptionString(string(expected))
}
Loading
Loading