Skip to content

Commit

Permalink
chore: Resolve issues and document account resource (#3360)
Browse files Browse the repository at this point in the history
## Changes
- Adjust task test as part of SNOW-1843489 (it turned out the logic is
correct, but the behavior was confusing; documented in code)
- Adjusted ticket numbers to corresponding issues for account/task
- Add a note in the account documentation about undetected changes for
certain fields (SNOW-1299979)

## For future
- When account issues will be addressed change ticket numbers.
  • Loading branch information
sfc-gh-jcieslak authored Jan 30, 2025
1 parent 89f2b0a commit 46b7a9d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
6 changes: 4 additions & 2 deletions docs/resources/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
page_title: "snowflake_account Resource - terraform-provider-snowflake"
subcategory: ""
description: |-
The account resource allows you to create and manage Snowflake accounts.
The account resource allows you to create and manage Snowflake accounts. For more information, check account documentation https://docs.snowflake.com/en/user-guide/organizations-manage-accounts.
---

# snowflake_account (Resource)

The account resource allows you to create and manage Snowflake accounts.
The account resource allows you to create and manage Snowflake accounts. For more information, check [account documentation](https://docs.snowflake.com/en/user-guide/organizations-manage-accounts).

~> **Note** To use this resource you have to use an account with a privilege to use the ORGADMIN role.

~> **Note** Changes for the following fields won't be detected: `admin_name`, `admin_password`, `admin_rsa_public_key`, `admin_user_type`, `first_name`, `last_name`, `email`, `must_change_password`. This is because these fields only supply initial values for creating the admin user. Once the account is created, the admin user becomes an independent entity. Modifying users from the account resource is challenging since it requires logging into that account. This would require the account resource logging into the account it created to read or alter admin user properties, which is impractical, because any external change to the admin user would disrupt the change detection anyway.

## Example Usage

```terraform
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var accountSchema = map[string]*schema.Schema{

func Account() *schema.Resource {
return &schema.Resource{
Description: "The account resource allows you to create and manage Snowflake accounts.",
Description: "The account resource allows you to create and manage Snowflake accounts. For more information, check [account documentation](https://docs.snowflake.com/en/user-guide/organizations-manage-accounts).",
CreateContext: TrackingCreateWrapper(resources.Account, CreateAccount),
ReadContext: TrackingReadWrapper(resources.Account, ReadAccount(true)),
UpdateContext: TrackingUpdateWrapper(resources.Account, UpdateAccount),
Expand Down
23 changes: 13 additions & 10 deletions pkg/resources/task_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strconv"
"testing"

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

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"
configvariable "github.com/hashicorp/terraform-plugin-testing/config"

Expand Down Expand Up @@ -1678,11 +1680,11 @@ func TestAcc_Task_ConvertStandaloneTaskToFinalizer(t *testing.T) {
WithFinalize(rootTaskId.FullyQualifiedName())
childTaskModel.SetDependsOn(rootTaskModel.ResourceReference())

firstTaskStandaloneModelDisabled := model.TaskWithId("root", rootTaskId, false, statement).
rootTaskStandaloneModelDisabled := model.TaskWithId("root", rootTaskId, false, statement).
WithScheduleMinutes(schedule)
secondTaskStandaloneModelDisabled := model.TaskWithId("child", finalizerTaskId, false, statement).
childTaskStandaloneModelDisabled := model.TaskWithId("child", finalizerTaskId, false, statement).
WithScheduleMinutes(schedule)
secondTaskStandaloneModelDisabled.SetDependsOn(firstTaskStandaloneModelDisabled.ResourceReference())
childTaskStandaloneModelDisabled.SetDependsOn(rootTaskStandaloneModelDisabled.ResourceReference())

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Expand Down Expand Up @@ -1724,9 +1726,10 @@ func TestAcc_Task_ConvertStandaloneTaskToFinalizer(t *testing.T) {
HasSuspendTaskAfterNumFailuresString("2"),
resourceshowoutputassert.TaskShowOutput(t, rootTaskModel.ResourceReference()).
HasScheduleMinutes(schedule).
// TODO(SNOW-1843489): Create ticket and report; this field in task relations seems to have mixed chances of appearing (needs deeper digging, doesn't affect the resource; could be removed for now)
// HasTaskRelations(sdk.TaskRelations{FinalizerTask: &finalizerTaskId}).
HasState(sdk.TaskStateStarted),
// For task relations to be present, in show_output we would have to modify the root task in a way that would
// trigger show_output recomputing by our custom diff.
objectassert.Task(t, rootTaskId).HasTaskRelations(sdk.TaskRelations{FinalizerTask: &finalizerTaskId}),
resourceassert.TaskResource(t, childTaskModel.ResourceReference()).
HasStartedString(r.BooleanTrue),
resourceshowoutputassert.TaskShowOutput(t, childTaskModel.ResourceReference()).
Expand All @@ -1737,20 +1740,20 @@ func TestAcc_Task_ConvertStandaloneTaskToFinalizer(t *testing.T) {
// Change tasks in DAG to standalone tasks (disabled to check if resuming/suspending works correctly)
{
ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Task/with_task_dependency"),
ConfigVariables: config.ConfigVariablesFromModels(t, "tasks", firstTaskStandaloneModelDisabled, secondTaskStandaloneModelDisabled),
ConfigVariables: config.ConfigVariablesFromModels(t, "tasks", rootTaskStandaloneModelDisabled, childTaskStandaloneModelDisabled),
Check: assert.AssertThat(t,
resourceassert.TaskResource(t, firstTaskStandaloneModelDisabled.ResourceReference()).
resourceassert.TaskResource(t, rootTaskStandaloneModelDisabled.ResourceReference()).
HasScheduleMinutes(schedule).
HasStartedString(r.BooleanFalse).
HasSuspendTaskAfterNumFailuresString("10"),
resourceshowoutputassert.TaskShowOutput(t, firstTaskStandaloneModelDisabled.ResourceReference()).
resourceshowoutputassert.TaskShowOutput(t, rootTaskStandaloneModelDisabled.ResourceReference()).
HasScheduleMinutes(schedule).
HasTaskRelations(sdk.TaskRelations{}).
HasState(sdk.TaskStateSuspended),
resourceassert.TaskResource(t, secondTaskStandaloneModelDisabled.ResourceReference()).
resourceassert.TaskResource(t, childTaskStandaloneModelDisabled.ResourceReference()).
HasScheduleMinutes(schedule).
HasStartedString(r.BooleanFalse),
resourceshowoutputassert.TaskShowOutput(t, secondTaskStandaloneModelDisabled.ResourceReference()).
resourceshowoutputassert.TaskShowOutput(t, childTaskStandaloneModelDisabled.ResourceReference()).
HasScheduleMinutes(schedule).
HasTaskRelations(sdk.TaskRelations{}).
HasState(sdk.TaskStateSuspended),
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/testint/accounts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestInt_Account(t *testing.T) {
RegionGroup: sdk.String("PUBLIC"),
Region: sdk.String(currentRegion.SnowflakeRegion),
Comment: sdk.String(comment),
// TODO(SNOW-1844776): with polaris Snowflake returns an error saying: "invalid property polaris for account"
// TODO(SNOW-1895880): with polaris Snowflake returns an error saying: "invalid property polaris for account"
// Polaris: sdk.Bool(true),
})
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/testint/tasks_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func TestInt_Tasks(t *testing.T) {
t.Cleanup(taskCleanup)

err := client.Tasks.Alter(ctx, sdk.NewAlterTaskRequest(task.ID()).WithSet(*sdk.NewTaskSetRequest().
// TODO(SNOW-1843489): Cannot set warehouse due to Snowflake error
// TODO(SNOW-1519496): Cannot set warehouse due to Snowflake error
// WithWarehouse(testClientHelper().Ids.WarehouseId()).
WithErrorIntegration(errorIntegration.ID()).
WithSessionParameters(sessionParametersSet).
Expand Down
2 changes: 2 additions & 0 deletions templates/resources/account.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ description: |-

~> **Note** To use this resource you have to use an account with a privilege to use the ORGADMIN role.

~> **Note** Changes for the following fields won't be detected: `admin_name`, `admin_password`, `admin_rsa_public_key`, `admin_user_type`, `first_name`, `last_name`, `email`, `must_change_password`. This is because these fields only supply initial values for creating the admin user. Once the account is created, the admin user becomes an independent entity. Modifying users from the account resource is challenging since it requires logging into that account. This would require the account resource logging into the account it created to read or alter admin user properties, which is impractical, because any external change to the admin user would disrupt the change detection anyway.

{{ if .HasExample -}}
## Example Usage

Expand Down

0 comments on commit 46b7a9d

Please sign in to comment.