Skip to content

Commit

Permalink
feat: Rework config hierarchy (#3166)
Browse files Browse the repository at this point in the history
<!-- Feel free to delete comments as you fill this in -->
- add remaining fields to the schema
- deprecate `account`
- implement and use a helper function for matching provider versions in
acceptance tests
- use helpers to fill config values
- add acceptance tests for all fields in the config
- move some code to internal package
- improve documentation: describe config hierarchy and provide better
config file examples
- improve and test sdk.MergeConfig
- move mock helper to a separate package because it caused unnecessarily
registered `sqlmock` driver in one of the tests
<!-- summary of changes -->

## Test Plan
<!-- detail ways in which this PR has been tested or needs to be tested
-->
* [x] acceptance tests
<!-- add more below if you think they are relevant -->
* [x] unit tests

## References
<!-- issues documentation links, etc  -->


#1881

#2145

#2925

#2983

#3104

## TODO
- acceptance test for fields regarding private keys - will be done in
SNOW-1754319
- unskip some tests after creating a compatible config for older
versions
  • Loading branch information
sfc-gh-jmichalak authored Nov 7, 2024
1 parent edc46cc commit 04cd9f0
Show file tree
Hide file tree
Showing 46 changed files with 1,890 additions and 550 deletions.
25 changes: 25 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ Please adjust your Terraform configuration files.
### *(behavior change)* Provider configuration rework
On our road to v1, we have decided to rework configuration to address the most common issues (see a [roadmap entry](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#providers-configuration-rework)). We have created a list of topics we wanted to address before v1. We will prepare an announcement soon. The following subsections describe the things addressed in the v0.98.0.

#### *(behavior change)* new fields
We have added new fields to match the ones in [the driver](https://pkg.go.dev/github.com/snowflakedb/gosnowflake#Config) and to simplify setting account name. Specifically:
- `include_retry_reason`, `max_retry_count`, `driver_tracing`, `tmp_directory_path` and `disable_console_login` are the new fields that are supported in the driver
- `disable_saml_url_check` will be added to the provider after upgrading the driver
- `account_name` and `organization_name` were added to improve handling account names. Read more in [docs](https://docs.snowflake.com/en/user-guide/admin-account-identifier#using-an-account-name-as-an-identifier).

#### *(behavior change)* changed configuration of driver log level
To be more consistent with other configuration options, we have decided to add `driver_tracing` to the configuration schema. This value can also be configured by `SNOWFLAKE_DRIVER_TRACING` environmental variable and by `drivertracing` field in the TOML file. The previous `SF_TF_GOSNOWFLAKE_LOG_LEVEL` environmental variable is not supported now, and was removed from the provider.

#### *(behavior change)* deprecated fields
Because of new fields `account_name` and `organization_name`, `account` is now deprecated. It will be removed before v1. Please adjust your configurations from
```terraform
provider "snowflake" {
account = "ORGANIZATION-ACCOUNT"
}
```

to
```terraform
provider "snowflake" {
organization_name = "ORGANIZATION"
account_name = "ACCOUNT"
}
```

#### *(behavior change)* changed behavior of some fields
For the fields that are not deprecated, we focused on improving validations and documentation. Also, we adjusted some fields to match our [driver's](https://github.com/snowflakedb/gosnowflake) defaults. Specifically:
- Relaxed validations for enum fields like `protocol` and `authenticator`. Now, the case on such fields is ignored.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test-architecture: ## check architecture constraints between packages
go test ./pkg/architests/... -v

test-client: ## runs test that checks sdk.Client without instrumentedsql
SF_TF_NO_INSTRUMENTED_SQL=1 SF_TF_GOSNOWFLAKE_LOG_LEVEL=debug go test ./pkg/sdk/internal/client/... -v
SF_TF_NO_INSTRUMENTED_SQL=1 go test ./pkg/sdk/internal/client/... -v

test-object-renaming: ## runs tests in object_renaming_acceptance_test.go
TEST_SF_TF_ENABLE_OBJECT_RENAMING=1 go test ./pkg/resources/object_renaming_acceptace_test.go -v
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Some links that might help you:
- The [issues section](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues) might already have an issue addressing your question.

## Would you like to create an issue?
If you would like to create a GitHub issue, please read our [guide](./CREATING_ISSUES.md) first.
If you would like to create a GitHub issue, please read our [guide](./CREATING_ISSUES.md) first.
It contains useful links, FAQ, and commonly known issues with solutions that may already solve your case.

## Additional debug logs for `snowflake_grant_privileges_to_role` resource
Expand All @@ -89,17 +89,17 @@ Set environment variable `SF_TF_ADDITIONAL_DEBUG_LOGGING` to a non-empty value.
## Additional SQL Client configuration
Currently underlying sql [gosnowflake](https://github.com/snowflakedb/gosnowflake) driver is wrapped with [instrumentedsql](https://github.com/luna-duclos/instrumentedsql). In order to use raw [gosnowflake](https://github.com/snowflakedb/gosnowflake) driver, set environment variable `SF_TF_NO_INSTRUMENTED_SQL` to a non-empty value.

By default, the underlying driver is set to error level logging. It can be changed by setting `SF_TF_GOSNOWFLAKE_LOG_LEVEL` to one of:
- `panic`
- `fatal`
- `error`
- `warn`
- `warning`
- `info`
- `debug`
By default, the underlying driver is set to error level logging. It can be changed by setting `driver_tracing` field in the configuration to one of (from most to least verbose):
- `trace`
- `debug`
- `info`
- `print`
- `warning`
- `error`
- `fatal`
- `panic`

*note*: It's possible it will be one of the provider config parameters in the future provider versions.
Read more in [provider configuration docs](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs#schema).

## Contributing

Expand Down
Loading

0 comments on commit 04cd9f0

Please sign in to comment.