diff --git a/docs/index.md b/docs/index.md index 2c5f0f4ea6..f6e9f2cfd6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -97,7 +97,7 @@ provider "snowflake" { - `passcode_in_password` (Boolean) False by default. Set to true if the MFA passcode is embedded to the configured password. Can also be sourced from the `SNOWFLAKE_PASSCODE_IN_PASSWORD` environment variable. - `password` (String, Sensitive) Password for user + password auth. Cannot be used with `browser_auth` or `private_key_path`. Can also be sourced from the `SNOWFLAKE_PASSWORD` environment variable. - `port` (Number) Specifies a custom port value used by the driver for privatelink connections. Can also be sourced from the `SNOWFLAKE_PORT` environment variable. -- `private_key` (String, Sensitive) Private Key for username+private-key auth. Cannot be used with `browser_auth` or `password`. Can also be sourced from the `SNOWFLAKE_PRIVATE_KEY` environment variable. +- `private_key` (String, Sensitive) Private Key for username+private-key auth. Cannot be used with `password`. Can also be sourced from the `SNOWFLAKE_PRIVATE_KEY` environment variable. - `private_key_passphrase` (String, Sensitive) Supports the encryption ciphers aes-128-cbc, aes-128-gcm, aes-192-cbc, aes-192-gcm, aes-256-cbc, aes-256-gcm, and des-ede3-cbc. Can also be sourced from the `SNOWFLAKE_PRIVATE_KEY_PASSPHRASE` environment variable. - `profile` (String) Sets the profile to read from ~/.snowflake/config file. Can also be sourced from the `SNOWFLAKE_PROFILE` environment variable. - `protocol` (String) A protocol used in the connection. Valid options are: `http` | `https`. Can also be sourced from the `SNOWFLAKE_PROTOCOL` environment variable. diff --git a/pkg/internal/snowflakeenvs/snowflake_environment_variables.go b/pkg/internal/snowflakeenvs/snowflake_environment_variables.go index 91f817c655..8440f0092c 100644 --- a/pkg/internal/snowflakeenvs/snowflake_environment_variables.go +++ b/pkg/internal/snowflakeenvs/snowflake_environment_variables.go @@ -1,11 +1,9 @@ package snowflakeenvs const ( - Account = "SNOWFLAKE_ACCOUNT" AccountName = "SNOWFLAKE_ACCOUNT_NAME" OrganizationName = "SNOWFLAKE_ORGANIZATION_NAME" User = "SNOWFLAKE_USER" - Username = "SNOWFLAKE_USERNAME" Password = "SNOWFLAKE_PASSWORD" Warehouse = "SNOWFLAKE_WAREHOUSE" Role = "SNOWFLAKE_ROLE" diff --git a/pkg/provider/provider_acceptance_test.go b/pkg/provider/provider_acceptance_test.go index 0ebc747b7f..9b8dcca9fa 100644 --- a/pkg/provider/provider_acceptance_test.go +++ b/pkg/provider/provider_acceptance_test.go @@ -30,7 +30,6 @@ func TestAcc_Provider_configHierarchy(t *testing.T) { user := acc.DefaultConfig(t).User pass := acc.DefaultConfig(t).Password - account := acc.DefaultConfig(t).Account role := acc.DefaultConfig(t).Role host := acc.DefaultConfig(t).Host @@ -104,7 +103,11 @@ func TestAcc_Provider_configHierarchy(t *testing.T) { testenvs.AssertEnvSet(t, snowflakeenvs.ConfigPath) t.Setenv(snowflakeenvs.User, user) t.Setenv(snowflakeenvs.Password, pass) - t.Setenv(snowflakeenvs.Account, account) + + accountId := configAccountId(t, acc.DefaultConfig(t)) + t.Setenv(snowflakeenvs.OrganizationName, accountId.OrganizationName()) + t.Setenv(snowflakeenvs.AccountName, accountId.AccountName()) + t.Setenv(snowflakeenvs.Role, role) t.Setenv(snowflakeenvs.Host, host) }, @@ -117,7 +120,8 @@ func TestAcc_Provider_configHierarchy(t *testing.T) { testenvs.AssertEnvSet(t, snowflakeenvs.ConfigPath) testenvs.AssertEnvSet(t, snowflakeenvs.User) testenvs.AssertEnvSet(t, snowflakeenvs.Password) - testenvs.AssertEnvSet(t, snowflakeenvs.Account) + testenvs.AssertEnvSet(t, snowflakeenvs.OrganizationName) + testenvs.AssertEnvSet(t, snowflakeenvs.AccountName) testenvs.AssertEnvSet(t, snowflakeenvs.Role) testenvs.AssertEnvSet(t, snowflakeenvs.Host) }, @@ -130,6 +134,13 @@ func TestAcc_Provider_configHierarchy(t *testing.T) { }) } +func configAccountId(t *testing.T, cfg *gosnowflake.Config) sdk.AccountIdentifier { + t.Helper() + accountIdRaw := cfg.Account + parts := strings.SplitN(accountIdRaw, "-", 2) + return sdk.NewAccountIdentifier(parts[0], parts[1]) +} + func TestAcc_Provider_configureClientOnceSwitching(t *testing.T) { t.Setenv(string(testenvs.ConfigureClientOnce), "") diff --git a/pkg/sdk/client_integration_test.go b/pkg/sdk/client_integration_test.go index 57522f9fae..9e2697a286 100644 --- a/pkg/sdk/client_integration_test.go +++ b/pkg/sdk/client_integration_test.go @@ -44,8 +44,9 @@ func TestClient_NewClient(t *testing.T) { require.NoError(t, err) require.NotNil(t, config) - account := config.Account - t.Setenv(snowflakeenvs.Account, account) + account := configAccountId(t, config) + t.Setenv(snowflakeenvs.OrganizationName, account.OrganizationName()) + t.Setenv(snowflakeenvs.OrganizationName, account.AccountName()) dir, err := os.UserHomeDir() require.NoError(t, err) diff --git a/pkg/sdk/config.go b/pkg/sdk/config.go index ce82b50111..a49884a5b0 100644 --- a/pkg/sdk/config.go +++ b/pkg/sdk/config.go @@ -214,7 +214,6 @@ func GetConfigFileName() (string, error) { // TODO(SNOW-1787920): improve TOML parsing type ConfigDTO struct { - Account *string `toml:"account"` AccountName *string `toml:"accountname"` OrganizationName *string `toml:"organizationname"` User *string `toml:"user"` @@ -257,7 +256,6 @@ type ConfigDTO struct { func (c *ConfigDTO) DriverConfig() (gosnowflake.Config, error) { driverCfg := gosnowflake.Config{} - pointerAttributeSet(c.Account, &driverCfg.Account) if c.AccountName != nil && c.OrganizationName != nil { driverCfg.Account = fmt.Sprintf("%s-%s", *c.OrganizationName, *c.AccountName) } diff --git a/pkg/sdk/config_test.go b/pkg/sdk/config_test.go index 436e09e661..4157afaa01 100644 --- a/pkg/sdk/config_test.go +++ b/pkg/sdk/config_test.go @@ -20,13 +20,15 @@ import ( func TestLoadConfigFile(t *testing.T) { c := ` [default] - account='TEST_ACCOUNT' + accountname='TEST_ACCOUNT' + organizationname='TEST_ORG' user='TEST_USER' password='abcd1234' role='ACCOUNTADMIN' [securityadmin] - account='TEST_ACCOUNT' + accountname='TEST_ACCOUNT' + organizationname='TEST_ORG' user='TEST_USER' password='abcd1234' role='SECURITYADMIN' @@ -35,11 +37,13 @@ func TestLoadConfigFile(t *testing.T) { m, err := loadConfigFile(configPath) require.NoError(t, err) - assert.Equal(t, "TEST_ACCOUNT", *m["default"].Account) + assert.Equal(t, "TEST_ACCOUNT", *m["default"].AccountName) + assert.Equal(t, "TEST_ORG", *m["default"].OrganizationName) assert.Equal(t, "TEST_USER", *m["default"].User) assert.Equal(t, "abcd1234", *m["default"].Password) assert.Equal(t, "ACCOUNTADMIN", *m["default"].Role) - assert.Equal(t, "TEST_ACCOUNT", *m["securityadmin"].Account) + assert.Equal(t, "TEST_ACCOUNT", *m["securityadmin"].AccountName) + assert.Equal(t, "TEST_ORG", *m["securityadmin"].OrganizationName) assert.Equal(t, "TEST_USER", *m["securityadmin"].User) assert.Equal(t, "abcd1234", *m["securityadmin"].Password) assert.Equal(t, "SECURITYADMIN", *m["securityadmin"].Role) @@ -71,7 +75,7 @@ func TestProfileConfig(t *testing.T) { jwtexpiretimeout=50 externalbrowsertimeout=60 maxretrycount=1 - authenticator='jwt' + authenticator='SNOWFLAKE_JWT' insecuremode=true ocspfailopen=true token='token' diff --git a/pkg/sdk/helper_test.go b/pkg/sdk/helper_test.go index fd82cb3665..5f2c2e362c 100644 --- a/pkg/sdk/helper_test.go +++ b/pkg/sdk/helper_test.go @@ -1,9 +1,11 @@ package sdk import ( + "strings" "testing" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testprofiles" + "github.com/snowflakedb/gosnowflake" ) func defaultTestClient(t *testing.T) *Client { @@ -46,3 +48,10 @@ func testClient(t *testing.T, profile string) *Client { return client } + +func configAccountId(t *testing.T, cfg *gosnowflake.Config) AccountIdentifier { + t.Helper() + accountIdRaw := cfg.Account + parts := strings.SplitN(accountIdRaw, "-", 2) + return NewAccountIdentifier(parts[0], parts[1]) +}