From 18638fea4c498158c8840a3ccfe03bdaac942923 Mon Sep 17 00:00:00 2001 From: Scott Winkler Date: Thu, 18 Jan 2024 22:15:22 -0800 Subject: [PATCH] chore: 0.84 release (#2374) fix sweepers. currently `SHOW DATABASES` also returns applications, so `DROP DATABASE XXX` will fail on it. Once we get Applications added to SDK then we can do `DROP APPLICATION XXX` instead --- pkg/resources/resource_monitor_acceptance_test.go | 4 ++-- pkg/resources/table_constraint.go | 10 ++++------ pkg/resources/tag_association.go | 10 ++++------ pkg/resources/tag_masking_policy_association.go | 9 ++++----- pkg/sdk/sweepers.go | 6 +++++- .../testint/application_packages_integration_test.go | 2 +- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/pkg/resources/resource_monitor_acceptance_test.go b/pkg/resources/resource_monitor_acceptance_test.go index ff121977ca..0738d4c007 100644 --- a/pkg/resources/resource_monitor_acceptance_test.go +++ b/pkg/resources/resource_monitor_acceptance_test.go @@ -107,7 +107,7 @@ func TestAcc_ResourceMonitorChangeStartEndTimestamp(t *testing.T) { func resourceMonitorConfigUpdatedTimestamp(accName string) string { return fmt.Sprintf(` resource "snowflake_warehouse" "warehouse" { - name = "test" + name = "test%v" comment = "foo" warehouse_size = "XSMALL" } @@ -119,7 +119,7 @@ resource "snowflake_resource_monitor" "test" { end_timestamp = "2056-01-01 12:00" } -`, accName) +`, accName, accName) } // fix 2 added empy notifiy user diff --git a/pkg/resources/table_constraint.go b/pkg/resources/table_constraint.go index 1d15395f20..5cbb79d8a3 100644 --- a/pkg/resources/table_constraint.go +++ b/pkg/resources/table_constraint.go @@ -6,7 +6,6 @@ import ( "log" "strings" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/snowflake" snowflakeValidation "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/validation" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -33,11 +32,10 @@ var tableConstraintSchema = map[string]*schema.Schema{ }, }, "table_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Idenfifier for table to create constraint on. Must be of the form Note: format must follow: \"\".\"\".\"\" or \"..\" or \"|.\" (snowflake_table.my_table.id)", - ValidateDiagFunc: IsValidIdentifier[sdk.SchemaObjectIdentifier](), + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Idenfifier for table to create constraint on. Must be of the form Note: format must follow: \"\".\"\".\"\" or \"..\" or \"|.\" (snowflake_table.my_table.id)", }, "columns": { Type: schema.TypeList, diff --git a/pkg/resources/tag_association.go b/pkg/resources/tag_association.go index 273d94cca6..4ad83996bb 100644 --- a/pkg/resources/tag_association.go +++ b/pkg/resources/tag_association.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/snowflake" snowflakeValidation "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/validation" ) @@ -65,11 +64,10 @@ var tagAssociationSchema = map[string]*schema.Schema{ ForceNew: true, }, "tag_id": { - Type: schema.TypeString, - Required: true, - Description: "Specifies the identifier for the tag. Note: format must follow: \"databaseName\".\"schemaName\".\"tagName\" or \"databaseName.schemaName.tagName\" or \"databaseName|schemaName.tagName\" (snowflake_tag.tag.id)", - ValidateDiagFunc: IsValidIdentifier[sdk.SchemaObjectIdentifier](), - ForceNew: true, + Type: schema.TypeString, + Required: true, + Description: "Specifies the identifier for the tag. Note: format must follow: \"databaseName\".\"schemaName\".\"tagName\" or \"databaseName.schemaName.tagName\" or \"databaseName|schemaName.tagName\" (snowflake_tag.tag.id)", + ForceNew: true, }, "tag_value": { Type: schema.TypeString, diff --git a/pkg/resources/tag_masking_policy_association.go b/pkg/resources/tag_masking_policy_association.go index 445b384218..c1f2df9758 100644 --- a/pkg/resources/tag_masking_policy_association.go +++ b/pkg/resources/tag_masking_policy_association.go @@ -23,11 +23,10 @@ const ( var mpAttachmentPolicySchema = map[string]*schema.Schema{ "tag_id": { - Type: schema.TypeString, - Required: true, - Description: "Specifies the identifier for the tag. Note: format must follow: \"databaseName\".\"schemaName\".\"tagName\" or \"databaseName.schemaName.tagName\" or \"databaseName|schemaName.tagName\" (snowflake_tag.tag.id)", - ValidateDiagFunc: IsValidIdentifier[sdk.SchemaObjectIdentifier](), - ForceNew: true, + Type: schema.TypeString, + Required: true, + Description: "Specifies the identifier for the tag. Note: format must follow: \"databaseName\".\"schemaName\".\"tagName\" or \"databaseName.schemaName.tagName\" or \"databaseName|schemaName.tagName\" (snowflake_tag.tag.id)", + ForceNew: true, }, "masking_policy_id": { Type: schema.TypeString, diff --git a/pkg/sdk/sweepers.go b/pkg/sdk/sweepers.go index 605ee3cc13..68d37e6312 100644 --- a/pkg/sdk/sweepers.go +++ b/pkg/sdk/sweepers.go @@ -172,7 +172,11 @@ func getDatabaseSweeper(client *Client, prefix string) func() error { if (prefix == "" || strings.HasPrefix(db.Name, prefix)) && db.Name != "SNOWFLAKE" && db.Name != "terraform_test_database" { log.Printf("[DEBUG] Dropping database %s", db.Name) if err := client.Databases.Drop(ctx, db.ID(), nil); err != nil { - return err + if strings.Contains(err.Error(), "Object found is of type 'APPLICATION', not specified type 'DATABASE'") { + log.Printf("[DEBUG] Skipping database %s", db.Name) + } else { + return err + } } } else { log.Printf("[DEBUG] Skipping database %s", db.Name) diff --git a/pkg/sdk/testint/application_packages_integration_test.go b/pkg/sdk/testint/application_packages_integration_test.go index 7724b0e1c6..52958249ab 100644 --- a/pkg/sdk/testint/application_packages_integration_test.go +++ b/pkg/sdk/testint/application_packages_integration_test.go @@ -201,7 +201,7 @@ func TestInt_ApplicationPackagesVersionAndReleaseDirective(t *testing.T) { createApplicationPackageHandle := func(t *testing.T) *sdk.ApplicationPackage { t.Helper() - id := sdk.NewAccountObjectIdentifier("snowflake_package_test") + id := sdk.RandomAccountObjectIdentifier() request := sdk.NewCreateApplicationPackageRequest(id).WithDistribution(sdk.DistributionPointer(sdk.DistributionInternal)) err := client.ApplicationPackages.Create(ctx, request) require.NoError(t, err)