Skip to content

Commit

Permalink
generate builders
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Dec 10, 2024
1 parent 31d43e0 commit 9406e0e
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 29 deletions.
15 changes: 9 additions & 6 deletions docs/resources/account_parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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).
<!-- TODO(SNOW-1634854): include an example showing both methods-->

Expand All @@ -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

Expand All @@ -43,5 +46,5 @@ resource "snowflake_account_parameter" "p2" {
Import is supported using the following syntax:

```shell
terraform import snowflake_account_parameter.p <parameter_name>
terraform import snowflake_account_parameter.p '<parameter_name>'
```

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.

2 changes: 1 addition & 1 deletion pkg/resources/account_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
57 changes: 35 additions & 22 deletions pkg/resources/account_parameter_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand All @@ -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"),
),
},
},
Expand All @@ -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) },
Expand All @@ -50,17 +57,18 @@ 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"),
),
},
},
})
}

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) },
Expand All @@ -70,17 +78,18 @@ 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"),
),
},
},
})
}

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) },
Expand All @@ -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{},
Expand All @@ -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) },
Expand All @@ -116,18 +126,21 @@ 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{},
},
},
})
}

// TODO(next pr): add more acc tests
// TODO(next pr): check unsetting in CheckDestroy
1 change: 1 addition & 0 deletions pkg/sdk/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 9406e0e

Please sign in to comment.