From 9406e0e51b39db0370a37c585bef2c20b5534698 Mon Sep 17 00:00:00 2001 From: Jakub Michalak Date: Tue, 10 Dec 2024 16:12:57 +0100 Subject: [PATCH] generate builders --- docs/resources/account_parameter.md | 15 ++-- .../account_parameter_resource_gen.go | 57 +++++++++++++++ .../model/account_parameter_model_gen.go | 70 +++++++++++++++++++ pkg/resources/account_parameter.go | 2 +- .../account_parameter_acceptance_test.go | 57 +++++++++------ pkg/sdk/parameters.go | 1 + 6 files changed, 173 insertions(+), 29 deletions(-) create mode 100644 pkg/acceptance/bettertestspoc/assert/resourceassert/account_parameter_resource_gen.go create mode 100644 pkg/acceptance/bettertestspoc/config/model/account_parameter_model_gen.go diff --git a/docs/resources/account_parameter.md b/docs/resources/account_parameter.md index 4607f52742..fb84bdc32f 100644 --- a/docs/resources/account_parameter.md +++ b/docs/resources/account_parameter.md @@ -2,12 +2,16 @@ page_title: "snowflake_account_parameter Resource - terraform-provider-snowflake" subcategory: "" description: |- - + Resource used to manage current account parameters. For more information, check parameters documentation https://docs.snowflake.com/en/sql-reference/parameters. --- -# snowflake_account_parameter (Resource) +!> **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#v0990--v01000) to use it. + +-> **Note** This resource does not support all account parameters. The supported ones are listed below. This feature gap will be addressed in future releases. +# snowflake_account_parameter (Resource) +Resource used to manage current account parameters. For more information, check [parameters documentation](https://docs.snowflake.com/en/sql-reference/parameters). ## Example Usage @@ -22,7 +26,6 @@ resource "snowflake_account_parameter" "p2" { value = "256" } ``` - -> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). @@ -31,8 +34,8 @@ resource "snowflake_account_parameter" "p2" { ### Required -- `key` (String) Name of account parameter. Valid values are those in [account parameters](https://docs.snowflake.com/en/sql-reference/parameters.html#account-parameters). -- `value` (String) Value of account parameter, as a string. Constraints are the same as those for the parameters in Snowflake documentation. +- `key` (String) Name of account parameter. Valid values are (case-insensitive): `ALLOW_CLIENT_MFA_CACHING` | `ALLOW_ID_TOKEN` | `CLIENT_ENCRYPTION_KEY_SIZE` | `ENABLE_IDENTIFIER_FIRST_LOGIN` | `ENABLE_INTERNAL_STAGES_PRIVATELINK` | `ENABLE_TRI_SECRET_AND_REKEY_OPT_OUT_FOR_IMAGE_REPOSITORY` | `ENABLE_TRI_SECRET_AND_REKEY_OPT_OUT_FOR_SPCS_BLOCK_STORAGE` | `EVENT_TABLE` | `EXTERNAL_OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST` | `INITIAL_REPLICATION_SIZE_LIMIT_IN_TB` | `MIN_DATA_RETENTION_TIME_IN_DAYS` | `NETWORK_POLICY` | `OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST` | `PERIODIC_DATA_REKEYING` | `PREVENT_LOAD_FROM_INLINE_URL` | `PREVENT_UNLOAD_TO_INLINE_URL` | `PREVENT_UNLOAD_TO_INTERNAL_STAGES` | `REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION` | `REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_OPERATION` | `SSO_LOGIN_PAGE` | `ABORT_DETACHED_QUERY` | `AUTOCOMMIT` | `BINARY_INPUT_FORMAT` | `BINARY_OUTPUT_FORMAT` | `CLIENT_METADATA_REQUEST_USE_CONNECTION_CTX` | `CLIENT_METADATA_USE_SESSION_DATABASE` | `CLIENT_RESULT_COLUMN_CASE_INSENSITIVE` | `DATE_INPUT_FORMAT` | `DATE_OUTPUT_FORMAT` | `ERROR_ON_NONDETERMINISTIC_MERGE` | `ERROR_ON_NONDETERMINISTIC_UPDATE` | `GEOGRAPHY_OUTPUT_FORMAT` | `JSON_INDENT` | `LOCK_TIMEOUT` | `MULTI_STATEMENT_COUNT` | `QUERY_TAG` | `QUOTED_IDENTIFIERS_IGNORE_CASE` | `ROWS_PER_RESULTSET` | `S3_STAGE_VPCE_DNS_NAME` | `SIMULATED_DATA_SHARING_CONSUMER` | `STATEMENT_TIMEOUT_IN_SECONDS` | `STRICT_JSON_OUTPUT` | `TIME_INPUT_FORMAT` | `TIME_OUTPUT_FORMAT` | `TIMESTAMP_DAY_IS_ALWAYS_24H` | `TIMESTAMP_INPUT_FORMAT` | `TIMESTAMP_LTZ_OUTPUT_FORMAT` | `TIMESTAMP_NTZ_OUTPUT_FORMAT` | `TIMESTAMP_OUTPUT_FORMAT` | `TIMESTAMP_TYPE_MAPPING` | `TIMESTAMP_TZ_OUTPUT_FORMAT` | `TIMEZONE` | `TRANSACTION_ABORT_ON_ERROR` | `TRANSACTION_DEFAULT_ISOLATION_LEVEL` | `TWO_DIGIT_CENTURY_START` | `UNSUPPORTED_DDL_ACTION` | `USE_CACHED_RESULT` | `WEEK_OF_YEAR_POLICY` | `WEEK_START` | `CATALOG` | `DATA_RETENTION_TIME_IN_DAYS` | `DEFAULT_DDL_COLLATION` | `EXTERNAL_VOLUME` | `LOG_LEVEL` | `MAX_CONCURRENCY_LEVEL` | `MAX_DATA_EXTENSION_TIME_IN_DAYS` | `PIPE_EXECUTION_PAUSED` | `REPLACE_INVALID_CHARACTERS` | `STATEMENT_QUEUED_TIMEOUT_IN_SECONDS` | `STORAGE_SERIALIZATION_POLICY` | `SHARE_RESTRICTIONS` | `SUSPEND_TASK_AFTER_NUM_FAILURES` | `TRACE_LEVEL` | `USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE` | `USER_TASK_TIMEOUT_MS` | `TASK_AUTO_RETRY_ATTEMPTS` | `USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS` | `METRIC_LEVEL` | `ENABLE_CONSOLE_OUTPUT` | `ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR`. +- `value` (String) Value of account parameter, as a string. Constraints are the same as those for the parameters in Snowflake documentation. The parameter values are validated in Snowflake. ### Read-Only @@ -43,5 +46,5 @@ resource "snowflake_account_parameter" "p2" { Import is supported using the following syntax: ```shell -terraform import snowflake_account_parameter.p +terraform import snowflake_account_parameter.p '' ``` diff --git a/pkg/acceptance/bettertestspoc/assert/resourceassert/account_parameter_resource_gen.go b/pkg/acceptance/bettertestspoc/assert/resourceassert/account_parameter_resource_gen.go new file mode 100644 index 0000000000..a021e54a07 --- /dev/null +++ b/pkg/acceptance/bettertestspoc/assert/resourceassert/account_parameter_resource_gen.go @@ -0,0 +1,57 @@ +// Code generated by assertions generator; DO NOT EDIT. + +package resourceassert + +import ( + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" +) + +type AccountParameterResourceAssert struct { + *assert.ResourceAssert +} + +func AccountParameterResource(t *testing.T, name string) *AccountParameterResourceAssert { + t.Helper() + + return &AccountParameterResourceAssert{ + ResourceAssert: assert.NewResourceAssert(name, "resource"), + } +} + +func ImportedAccountParameterResource(t *testing.T, id string) *AccountParameterResourceAssert { + t.Helper() + + return &AccountParameterResourceAssert{ + ResourceAssert: assert.NewImportedResourceAssert(id, "imported resource"), + } +} + +/////////////////////////////////// +// Attribute value string checks // +/////////////////////////////////// + +func (a *AccountParameterResourceAssert) HasKeyString(expected string) *AccountParameterResourceAssert { + a.AddAssertion(assert.ValueSet("key", expected)) + return a +} + +func (a *AccountParameterResourceAssert) HasValueString(expected string) *AccountParameterResourceAssert { + a.AddAssertion(assert.ValueSet("value", expected)) + return a +} + +//////////////////////////// +// Attribute empty checks // +//////////////////////////// + +func (a *AccountParameterResourceAssert) HasNoKey() *AccountParameterResourceAssert { + a.AddAssertion(assert.ValueNotSet("key")) + return a +} + +func (a *AccountParameterResourceAssert) HasNoValue() *AccountParameterResourceAssert { + a.AddAssertion(assert.ValueNotSet("value")) + return a +} diff --git a/pkg/acceptance/bettertestspoc/config/model/account_parameter_model_gen.go b/pkg/acceptance/bettertestspoc/config/model/account_parameter_model_gen.go new file mode 100644 index 0000000000..9fc1cff42a --- /dev/null +++ b/pkg/acceptance/bettertestspoc/config/model/account_parameter_model_gen.go @@ -0,0 +1,70 @@ +// Code generated by config model builder generator; DO NOT EDIT. + +package model + +import ( + tfconfig "github.com/hashicorp/terraform-plugin-testing/config" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources" +) + +type AccountParameterModel struct { + Key tfconfig.Variable `json:"key,omitempty"` + Value tfconfig.Variable `json:"value,omitempty"` + + *config.ResourceModelMeta +} + +///////////////////////////////////////////////// +// Basic builders (resource name and required) // +///////////////////////////////////////////////// + +func AccountParameter( + resourceName string, + key string, + value string, +) *AccountParameterModel { + a := &AccountParameterModel{ResourceModelMeta: config.Meta(resourceName, resources.AccountParameter)} + a.WithKey(key) + a.WithValue(value) + return a +} + +func AccountParameterWithDefaultMeta( + key string, + value string, +) *AccountParameterModel { + a := &AccountParameterModel{ResourceModelMeta: config.DefaultMeta(resources.AccountParameter)} + a.WithKey(key) + a.WithValue(value) + return a +} + +///////////////////////////////// +// below all the proper values // +///////////////////////////////// + +func (a *AccountParameterModel) WithKey(key string) *AccountParameterModel { + a.Key = tfconfig.StringVariable(key) + return a +} + +func (a *AccountParameterModel) WithValue(value string) *AccountParameterModel { + a.Value = tfconfig.StringVariable(value) + return a +} + +////////////////////////////////////////// +// below it's possible to set any value // +////////////////////////////////////////// + +func (a *AccountParameterModel) WithKeyValue(value tfconfig.Variable) *AccountParameterModel { + a.Key = value + return a +} + +func (a *AccountParameterModel) WithValueValue(value tfconfig.Variable) *AccountParameterModel { + a.Value = value + return a +} diff --git a/pkg/resources/account_parameter.go b/pkg/resources/account_parameter.go index f8a782b1f2..2f8021c080 100644 --- a/pkg/resources/account_parameter.go +++ b/pkg/resources/account_parameter.go @@ -72,7 +72,7 @@ func ReadAccountParameter(ctx context.Context, d *schema.ResourceData, meta any) if err != nil { return diag.FromErr(err) } - parameter, err := client.Parameters.ShowAccountParameter(ctx, sdk.AccountParameter(parameterName)) + parameter, err := client.Parameters.ShowAccountParameter(ctx, parameterName) if err != nil { return diag.FromErr(fmt.Errorf("reading account parameter: %w", err)) } diff --git a/pkg/resources/account_parameter_acceptance_test.go b/pkg/resources/account_parameter_acceptance_test.go index 7af59dc238..1e61229df7 100644 --- a/pkg/resources/account_parameter_acceptance_test.go +++ b/pkg/resources/account_parameter_acceptance_test.go @@ -5,12 +5,18 @@ import ( "testing" acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceassert" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/model" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func TestAcc_AccountParameter(t *testing.T) { + model := model.AccountParameter("test", "ALLOW_ID_TOKEN", "true") resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -20,10 +26,10 @@ func TestAcc_AccountParameter(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: accountParameterBasic("ALLOW_ID_TOKEN", "true"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "ALLOW_ID_TOKEN"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "true"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterAllowIDToken)). + HasValueString("true"), ), }, }, @@ -41,6 +47,7 @@ resource "snowflake_account_parameter" "p" { } func TestAcc_AccountParameter_PREVENT_LOAD_FROM_INLINE_URL(t *testing.T) { + model := model.AccountParameter("test", string(sdk.AccountParameterPreventLoadFromInlineURL), "true") resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -50,10 +57,10 @@ func TestAcc_AccountParameter_PREVENT_LOAD_FROM_INLINE_URL(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: accountParameterBasic("PREVENT_LOAD_FROM_INLINE_URL", "true"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "PREVENT_LOAD_FROM_INLINE_URL"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "true"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterPreventLoadFromInlineURL)). + HasValueString("true"), ), }, }, @@ -61,6 +68,7 @@ func TestAcc_AccountParameter_PREVENT_LOAD_FROM_INLINE_URL(t *testing.T) { } func TestAcc_AccountParameter_REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION(t *testing.T) { + model := model.AccountParameter("test", string(sdk.AccountParameterRequireStorageIntegrationForStageCreation), "true") resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -70,10 +78,10 @@ func TestAcc_AccountParameter_REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION(t * CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: accountParameterBasic("REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION", "true"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "true"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterRequireStorageIntegrationForStageCreation)). + HasValueString("true"), ), }, }, @@ -81,6 +89,7 @@ func TestAcc_AccountParameter_REQUIRE_STORAGE_INTEGRATION_FOR_STAGE_CREATION(t * } func TestAcc_AccountParameter_Issue2573(t *testing.T) { + model := model.AccountParameter("test", string(sdk.AccountParameterTimezone), "Etc/UTC") resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -90,14 +99,14 @@ func TestAcc_AccountParameter_Issue2573(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: accountParameterBasic("TIMEZONE", "Etc/UTC"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "TIMEZONE"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "Etc/UTC"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterTimezone)). + HasValueString("Etc/UTC"), ), }, { - ResourceName: "snowflake_account_parameter.p", + ResourceName: "snowflake_account_parameter.test", ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{}, @@ -107,6 +116,7 @@ func TestAcc_AccountParameter_Issue2573(t *testing.T) { } func TestAcc_AccountParameter_Issue3025(t *testing.T) { + model := model.AccountParameter("test", string(sdk.AccountParameterOAuthAddPrivilegedRolesToBlockedList), "true") resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -116,14 +126,14 @@ func TestAcc_AccountParameter_Issue3025(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: accountParameterBasic("OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST", "true"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "key", "OAUTH_ADD_PRIVILEGED_ROLES_TO_BLOCKED_LIST"), - resource.TestCheckResourceAttr("snowflake_account_parameter.p", "value", "true"), + Config: config.FromModel(t, model), + Check: assert.AssertThat(t, resourceassert.AccountParameterResource(t, model.ResourceReference()). + HasKeyString(string(sdk.AccountParameterOAuthAddPrivilegedRolesToBlockedList)). + HasValueString("true"), ), }, { - ResourceName: "snowflake_account_parameter.p", + ResourceName: "snowflake_account_parameter.test", ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{}, @@ -131,3 +141,6 @@ func TestAcc_AccountParameter_Issue3025(t *testing.T) { }, }) } + +// TODO(next pr): add more acc tests +// TODO(next pr): check unsetting in CheckDestroy diff --git a/pkg/sdk/parameters.go b/pkg/sdk/parameters.go index 13576c4b72..ea1ddf66e7 100644 --- a/pkg/sdk/parameters.go +++ b/pkg/sdk/parameters.go @@ -176,6 +176,7 @@ func (parameters *parameters) SetAccountParameter(ctx context.Context, parameter return nil } +// TODO(next pr): add integration tests func (parameters *parameters) UnsetAccountParameter(ctx context.Context, parameter AccountParameter) error { opts := AlterAccountOptions{ Unset: &AccountUnset{