From a677547ac24c7b3f4d470b6f5fa3541341581fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Budzy=C5=84ski?= Date: Tue, 12 Nov 2024 15:40:50 +0100 Subject: [PATCH] adressed comments from connection fix --- docs/resources/primary_connection.md | 2 +- pkg/datasources/secrets_acceptance_test.go | 19 ++----- pkg/sdk/parsers_test.go | 56 +++++++++++++++---- .../resources/primary_connection.md.tmpl | 2 +- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/docs/resources/primary_connection.md b/docs/resources/primary_connection.md index c1efe4617b..446b21b754 100644 --- a/docs/resources/primary_connection.md +++ b/docs/resources/primary_connection.md @@ -29,7 +29,7 @@ resource "snowflake_primary_connection" "complete" { } ``` --> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](./docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). +-> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](../docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). -> **Note** To demote [`snowflake_primary_connection`](./primary_connection) to [`snowflake_secondary_connection`](./secondary_connection), resources need to be migrated manually. For guidance on removing and importing resources into the state check [resource migration](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md). Remove the resource from the state, then recreate it in manually using: ``` diff --git a/pkg/datasources/secrets_acceptance_test.go b/pkg/datasources/secrets_acceptance_test.go index f77b6e27ee..122755c052 100644 --- a/pkg/datasources/secrets_acceptance_test.go +++ b/pkg/datasources/secrets_acceptance_test.go @@ -20,13 +20,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/tfversion" ) -const ( - secretWithClientCredentials = "snowflake_secret_with_client_credentials" - secretWithAuthorizationCodeGrant = "snowflake_secret_with_authorization_code_grant" - secretWithBasicAuthentication = "snowflake_secret_with_basic_authentication" - secretWithGenericString = "snowflake_secret_with_generic_string" -) - func TestAcc_Secrets_WithClientCredentials(t *testing.T) { _ = testenvs.GetOrSkipTest(t, testenvs.EnableAcceptance) acc.TestAccPreCheck(t) @@ -42,7 +35,7 @@ func TestAcc_Secrets_WithClientCredentials(t *testing.T) { secretModel := model.SecretWithClientCredentials("test", integrationId.Name(), id.DatabaseName(), id.SchemaName(), id.Name(), []string{"username", "test_scope"}) - dataSecretsClientCredentials := accConfig.FromModel(t, secretModel) + secretsData(secretWithClientCredentials, id.DatabaseId().FullyQualifiedName()) + dataSecretsClientCredentials := accConfig.FromModel(t, secretModel) + secretsData(secretModel, id) dsName := "data.snowflake_secrets.test" resource.Test(t, resource.TestCase{ @@ -97,7 +90,7 @@ func TestAcc_Secrets_WithAuthorizationCodeGrant(t *testing.T) { secretModel := model.SecretWithAuthorizationCodeGrant("test", integrationId.Name(), id.DatabaseName(), id.SchemaName(), id.Name(), "test_token", time.Now().Add(24*time.Hour).Format(time.DateTime)).WithComment("test_comment") - dataSecretsAuthorizationCode := accConfig.FromModel(t, secretModel) + secretsData(secretWithAuthorizationCodeGrant, id.DatabaseId().FullyQualifiedName()) + dataSecretsAuthorizationCode := accConfig.FromModel(t, secretModel) + secretsData(secretModel, id) dsName := "data.snowflake_secrets.test" resource.Test(t, resource.TestCase{ @@ -138,7 +131,7 @@ func TestAcc_Secrets_WithBasicAuthentication(t *testing.T) { id := acc.TestClient().Ids.RandomSchemaObjectIdentifier() secretModel := model.SecretWithBasicAuthentication("test", id.DatabaseName(), id.Name(), "test_passwd", id.SchemaName(), "test_username") - dataSecretsAuthorizationCode := accConfig.FromModel(t, secretModel) + secretsData(secretWithBasicAuthentication, id.DatabaseId().FullyQualifiedName()) + dataSecretsAuthorizationCode := accConfig.FromModel(t, secretModel) + secretsData(secretModel, id) dsName := "data.snowflake_secrets.test" resource.Test(t, resource.TestCase{ @@ -179,7 +172,7 @@ func TestAcc_Secrets_WithGenericString(t *testing.T) { secretModel := model.SecretWithGenericString("test", id.DatabaseName(), id.Name(), id.SchemaName(), "test_secret_string") - dataSecretsAuthorizationCode := accConfig.FromModel(t, secretModel) + secretsData(secretWithGenericString, id.DatabaseId().FullyQualifiedName()) + dataSecretsAuthorizationCode := accConfig.FromModel(t, secretModel) + secretsData(secretModel, id) dsName := "data.snowflake_secrets.test" resource.Test(t, resource.TestCase{ @@ -216,14 +209,14 @@ func TestAcc_Secrets_WithGenericString(t *testing.T) { }) } -func secretsData(secretResourceName string, inDatabaseName string) string { +func secretsData(secretModel accConfig.ResourceModel, secretId sdk.SchemaObjectIdentifier) string { return fmt.Sprintf(` data "snowflake_secrets" "test" { depends_on = [%s.test] in { database = %s } - }`, secretResourceName, inDatabaseName) + }`, secretModel.Resource(), secretId.DatabaseId().FullyQualifiedName()) } func TestAcc_Secrets_Filtering(t *testing.T) { diff --git a/pkg/sdk/parsers_test.go b/pkg/sdk/parsers_test.go index 71faf01c23..6ee19ca2ad 100644 --- a/pkg/sdk/parsers_test.go +++ b/pkg/sdk/parsers_test.go @@ -168,6 +168,42 @@ func TestParseCommaSeparatedSchemaObjectIdentifierArray(t *testing.T) { } } +func TestParseCommaSeparatedSchemaObjectIdentifierArray_Invalid(t *testing.T) { + testCases := []struct { + Name string + Value string + Error string + }{ + { + Name: "bad quotes", + Value: `["a]`, + Error: "unable to read identifier: \"a, err = parse error on line 1, column 3: extraneous or missing \" in quoted-field", + }, + { + Name: "missing parts", + Value: "[a.b.c, a.b]", + Error: "unexpected number of parts 2 in identifier a.b, expected 3 in a form of \"..\"", + }, + { + Name: "too many parts", + Value: "[a.b.c, a.b.c.d]", + Error: "unexpected number of parts 4 in identifier a.b.c.d, expected 3 in a form of \"..\"", + }, + { + Name: "missing parts - empty id", + Value: "[a.b.c, ]", + Error: "incompatible identifier", + }, + } + + for _, tc := range testCases { + t.Run(tc.Name, func(t *testing.T) { + _, err := ParseCommaSeparatedSchemaObjectIdentifierArray(tc.Value) + require.ErrorContains(t, err, tc.Error) + }) + } +} + func TestParseCommaSeparatedAccountIdentifierArray(t *testing.T) { testCases := []struct { Name string @@ -230,37 +266,37 @@ func TestParseCommaSeparatedAccountIdentifierArray(t *testing.T) { } } -func TestParseCommaSeparatedSchemaObjectIdentifierArray_Invalid(t *testing.T) { +func TestParseCommaSeparatedAccountIdentifierArray_Invalid(t *testing.T) { testCases := []struct { Name string Value string Error string }{ { - Name: "bad quotes", - Value: `["a]`, - Error: "unable to read identifier: \"a, err = parse error on line 1, column 3: extraneous or missing \" in quoted-field", + Name: "invalid qoutes", + Value: `["a.b]`, + Error: "unable to read identifier: \"a.b, err = parse error on line 1, column 5: extraneous or missing \" in quoted-field", }, { Name: "missing parts", - Value: "[a.b.c, a.b]", - Error: "unexpected number of parts 2 in identifier a.b, expected 3 in a form of \"..\"", + Value: "[a.b, a]", + Error: "unexpected number of parts 1 in identifier a, expected 2 in a form of \".\"", }, { Name: "too many parts", - Value: "[a.b.c, a.b.c.d]", - Error: "unexpected number of parts 4 in identifier a.b.c.d, expected 3 in a form of \"..\"", + Value: "[a.b, a.b.c]", + Error: "unexpected number of parts 3 in identifier a.b.c, expected 2 in a form of \".\"", }, { Name: "missing parts - empty id", - Value: "[a.b.c, ]", + Value: "[a.b, ]", Error: "incompatible identifier", }, } for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { - _, err := ParseCommaSeparatedSchemaObjectIdentifierArray(tc.Value) + _, err := ParseCommaSeparatedAccountIdentifierArray(tc.Value) require.ErrorContains(t, err, tc.Error) }) } diff --git a/templates/resources/primary_connection.md.tmpl b/templates/resources/primary_connection.md.tmpl index e4841ffbd6..96467f5312 100644 --- a/templates/resources/primary_connection.md.tmpl +++ b/templates/resources/primary_connection.md.tmpl @@ -20,7 +20,7 @@ description: |- {{ tffile (printf "examples/resources/%s/resource.tf" .Name)}} --> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](./docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). +-> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](../docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). -> **Note** To demote [`snowflake_primary_connection`](./primary_connection) to [`snowflake_secondary_connection`](./secondary_connection), resources need to be migrated manually. For guidance on removing and importing resources into the state check [resource migration](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/resource_migration.md). Remove the resource from the state, then recreate it in manually using: ```