Skip to content

Commit

Permalink
feat: Task resource v1 readiness (#3113)
Browse files Browse the repository at this point in the history
## Changes
- Mostly done task resource refactor
- Sweepers test fixed (they always added errors even when they're nil)
- Minor changes in SDK (find out the bug with alter task and right now
we're only supporting upper-cased warehouse names; added that to the
field description)
- Acceptance tests
- The enabled field is not a three-valued boolean because it created
certain issues when updating the task. The task status is very important
for their management and working, so I decided to have them as regular
boolean values that are either true or false, nothing in between.

## Next prs
- Apply comments from
#3086
- Data source
- Move some of the logic to SDK
- Refactor SDK suspend root logic for tasks (and overall suspend logic
in SDK/resource)
- Examples, documentation, and migration guide
- More test cases for complicated DAG structures to show the resource
can handle more complex structures
- Analyze non-deterministic test cases
- Refactor task resuming in task resource (most likely with the use of
defer) because currently, there may be cases that error can cause tasks
to be not resumed.
- Test and see how the DAG of tasks could be owned by a role other than
the one created with Terraform (also with less privileges, only to run
the task).
- Make config without $$ escapes needed
- Check if more helper functions from user resource could be used in
task resource.
- Check in one acceptance test why finalizer task in show_output is not
set (is that Snowflake or mapping error).
- More tests for calling (`as` field) -
#3113 (comment)
- Re-generate and list all the issues with asserts and models
- check test tasks_gen_integration_test.go:937 (and see why it's non
deterministic).
- Support session paramters

## References
* [CREATE
TASK](https://docs.snowflake.com/en/sql-reference/sql/create-task)
  • Loading branch information
sfc-gh-jcieslak authored Nov 5, 2024
1 parent 9fd8f88 commit 0aba5c9
Show file tree
Hide file tree
Showing 53 changed files with 5,690 additions and 1,419 deletions.
4 changes: 2 additions & 2 deletions docs/resources/resource_monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
page_title: "snowflake_resource_monitor Resource - terraform-provider-snowflake"
subcategory: ""
description: |-
Resource used to manage resource monitor objects. For more information, check resource monitor documentation https://docs.snowflake.com/en/user-guide/resource-monitors.
---

!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0950--v0960) to use it.
Expand All @@ -15,7 +15,7 @@ description: |-

# snowflake_resource_monitor (Resource)


Resource used to manage resource monitor objects. For more information, check [resource monitor documentation](https://docs.snowflake.com/en/user-guide/resource-monitors).

## Example Usage

Expand Down
888 changes: 872 additions & 16 deletions docs/resources/task.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/acceptance/bettertestspoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,5 @@ func (w *WarehouseDatasourceShowOutputAssert) IsEmpty() {
1. Lists of objects are partially generated, and only parameter name is generated in some functions (the type has to be added manually).
2. `testing` is a package name that makes Go think that we want to have unnamed parameter there, but we just didn't generate the type for that field in the function argument.
- generate assertions checking that time is not empty - we often do not compare time fields by value, but check if they are set
- Additional asserts for sets and lists that wouldn't rely on the order of items saved to the state (SNOW-1706544)
- support generating provider config and use generated configs in `pkg/provider/provider_acceptance_test.go`
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,37 @@ func (t *TaskAssert) HasTaskRelations(expected sdk.TaskRelations) *TaskAssert {
})
return t
}

func (t *TaskAssert) HasWarehouse(expected *sdk.AccountObjectIdentifier) *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if o.Warehouse == nil && expected != nil {
return fmt.Errorf("expected warehouse to have value; got: nil")
}
if o.Warehouse != nil && expected == nil {
return fmt.Errorf("expected warehouse to no have value; got: %s", o.Warehouse.Name())
}
if o.Warehouse != nil && expected != nil && o.Warehouse.Name() != expected.Name() {
return fmt.Errorf("expected warehouse: %v; got: %v", expected.Name(), o.Warehouse.Name())
}
return nil
})
return t
}

func (t *TaskAssert) HasErrorIntegration(expected *sdk.AccountObjectIdentifier) *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if o.ErrorIntegration == nil && expected != nil {
return fmt.Errorf("expected error integration to have value; got: nil")
}
if o.ErrorIntegration != nil && expected == nil {
return fmt.Errorf("expected error integration to have no value; got: %s", o.ErrorIntegration.Name())
}
if o.ErrorIntegration != nil && expected != nil && o.ErrorIntegration.Name() != expected.Name() {
return fmt.Errorf("expected error integration: %v; got: %v", expected.Name(), o.ErrorIntegration.Name())
}
return nil
})
return t
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ var allResourceSchemaDefs = []ResourceSchemaDef{
name: "StreamOnView",
schema: resources.StreamOnView().Schema,
},
{
name: "Task",
schema: resources.Task().Schema,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package resourceassert

import (
"fmt"
"strconv"

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

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

func (t *TaskResourceAssert) HasAfterIds(ids ...sdk.SchemaObjectIdentifier) *TaskResourceAssert {
t.AddAssertion(assert.ValueSet("after.#", strconv.FormatInt(int64(len(ids)), 10)))
for i, id := range ids {
t.AddAssertion(assert.ValueSet(fmt.Sprintf("after.%d", i), id.FullyQualifiedName()))
}
return t
}
Loading

0 comments on commit 0aba5c9

Please sign in to comment.