Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Aug 13, 2024
1 parent d3a7c06 commit fc97d84
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docs/resources/account_password_policy_attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resource "snowflake_password_policy" "default" {
}
resource "snowflake_account_password_policy_attachment" "attachment" {
password_policy = snowflake_password_policy.default.qualified_name
password_policy = snowflake_password_policy.default.fully_qualified_name
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resource "snowflake_stream" "stream" {
schema = "schema"
name = "stream"
on_table = snowflake_table.table.qualified_name
on_table = snowflake_table.table.fully_qualified_name
append_only = false
insert_only = false
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/table_column_masking_policy_application.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ resource "snowflake_table" "table" {
resource "snowflake_table_column_masking_policy_application" "application" {
provider = snowflake.masking # Apply masking policy with masking_admin role
table = snowflake_table.table.qualified_name
table = snowflake_table.table.fully_qualified_name
column = "secret"
masking_policy = snowflake_masking_policy.policy.qualified_name
masking_policy = snowflake_masking_policy.policy.fully_qualified_name
}
```

Expand Down
8 changes: 4 additions & 4 deletions docs/resources/table_constraint.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ resource "snowflake_table" "fk_t" {
resource "snowflake_table_constraint" "primary_key" {
name = "myconstraint"
type = "PRIMARY KEY"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col1"]
comment = "hello world"
}
resource "snowflake_table_constraint" "foreign_key" {
name = "myconstraintfk"
type = "FOREIGN KEY"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col2"]
foreign_key_properties {
references {
table_id = snowflake_table.fk_t.qualified_name
table_id = snowflake_table.fk_t.fully_qualified_name
columns = ["fk_col1"]
}
}
Expand All @@ -91,7 +91,7 @@ resource "snowflake_table_constraint" "foreign_key" {
resource "snowflake_table_constraint" "unique" {
name = "unique"
type = "UNIQUE"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col3"]
comment = "hello unique"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ resource "snowflake_password_policy" "default" {
}

resource "snowflake_account_password_policy_attachment" "attachment" {
password_policy = snowflake_password_policy.default.qualified_name
password_policy = snowflake_password_policy.default.fully_qualified_name
}
2 changes: 1 addition & 1 deletion examples/resources/snowflake_stream/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource "snowflake_stream" "stream" {
schema = "schema"
name = "stream"

on_table = snowflake_table.table.qualified_name
on_table = snowflake_table.table.fully_qualified_name
append_only = false
insert_only = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ resource "snowflake_table" "table" {
resource "snowflake_table_column_masking_policy_application" "application" {
provider = snowflake.masking # Apply masking policy with masking_admin role

table = snowflake_table.table.qualified_name
table = snowflake_table.table.fully_qualified_name
column = "secret"
masking_policy = snowflake_masking_policy.policy.qualified_name
masking_policy = snowflake_masking_policy.policy.fully_qualified_name
}
8 changes: 4 additions & 4 deletions examples/resources/snowflake_table_constraint/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ resource "snowflake_table" "fk_t" {
resource "snowflake_table_constraint" "primary_key" {
name = "myconstraint"
type = "PRIMARY KEY"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col1"]
comment = "hello world"
}

resource "snowflake_table_constraint" "foreign_key" {
name = "myconstraintfk"
type = "FOREIGN KEY"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col2"]
foreign_key_properties {
references {
table_id = snowflake_table.fk_t.qualified_name
table_id = snowflake_table.fk_t.fully_qualified_name
columns = ["fk_col1"]
}
}
Expand All @@ -77,7 +77,7 @@ resource "snowflake_table_constraint" "foreign_key" {
resource "snowflake_table_constraint" "unique" {
name = "unique"
type = "UNIQUE"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col3"]
comment = "hello unique"
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "snowflake_password_policy" "pa" {
}
resource "snowflake_account_password_policy_attachment" "att" {
password_policy = snowflake_password_policy.pa.qualified_name
password_policy = snowflake_password_policy.pa.fully_qualified_name
}
`
return fmt.Sprintf(s, databaseName, schemaName, prefix)
Expand Down
6 changes: 2 additions & 4 deletions pkg/resources/external_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
Expand Down Expand Up @@ -197,9 +196,8 @@ func ExternalFunction() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

CustomizeDiff: customdiff.All(
ComputedIfAnyAttributeChanged(FullyQualifiedNameAttributeName, "arg"),
),
// TODO(SNOW-1348352): add `name` and `arguments` to ComputedIfAnyAttributeChanged for FullyQualifiedNameAttributeName.
// This can't be done now because this function compares values without diff suppress.

StateUpgraders: []schema.StateUpgrader{
{
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func Function() *schema.Resource {
DeleteContext: DeleteContextFunction,

CustomizeDiff: customdiff.All(
ComputedIfAnyAttributeChanged(FullyQualifiedNameAttributeName, "name", "arguments"),
// TODO(SNOW-1348103): add `arguments` to ComputedIfAnyAttributeChanged. This can't be done now because this function compares values without diff suppress.
ComputedIfAnyAttributeChanged(FullyQualifiedNameAttributeName, "name"),
),

Schema: functionSchema,
Expand Down
4 changes: 3 additions & 1 deletion pkg/resources/procedure.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ func Procedure() *schema.Resource {
UpdateContext: UpdateContextProcedure,
DeleteContext: DeleteContextProcedure,

// TODO(SNOW-1348106): add `arguments` to ComputedIfAnyAttributeChanged for FullyQualifiedNameAttributeName.
// This can't be done now because this function compares values without diff suppress.
CustomizeDiff: customdiff.All(
ComputedIfAnyAttributeChanged(FullyQualifiedNameAttributeName, "name", "arguments"),
ComputedIfAnyAttributeChanged(FullyQualifiedNameAttributeName, "name"),
),

Schema: procedureSchema,
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/table_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ resource "snowflake_table" "test_table" {
column {
name = "column1"
type = "VARCHAR(16)"
masking_policy = snowflake_masking_policy.%[4]s.qualified_name
masking_policy = snowflake_masking_policy.%[4]s.fully_qualified_name
}
}
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ resource "snowflake_table" "table" {
}
resource "snowflake_table_column_masking_policy_application" "mpa" {
table = snowflake_table.table.qualified_name
table = snowflake_table.table.fully_qualified_name
column = "secret"
masking_policy = snowflake_masking_policy.test.qualified_name
masking_policy = snowflake_masking_policy.test.fully_qualified_name
}`, databaseName, schemaName, databaseName, schemaName)
}
2 changes: 1 addition & 1 deletion pkg/resources/table_constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (v *tableConstraintID) parse(s string) {
func getTableIdentifier(s string) (*sdk.SchemaObjectIdentifier, error) {
var objectIdentifier sdk.ObjectIdentifier
var err error
// TODO [SNOW-999049]: Fallback for old implementations using table.id instead of table.qualified_name - probably will be removed later.
// TODO [SNOW-999049]: Fallback for old implementations using table.id instead of table.fully_qualified_name - probably will be removed later.
if strings.Contains(s, "|") {
objectIdentifier = helpers.DecodeSnowflakeID(s)
} else {
Expand Down
24 changes: 12 additions & 12 deletions pkg/resources/table_constraint_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ resource "snowflake_table" "fk_t" {
resource "snowflake_table_constraint" "fk" {
name="%s"
type= "FOREIGN KEY"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col1"]
foreign_key_properties {
references {
table_id = snowflake_table.fk_t.qualified_name
table_id = snowflake_table.fk_t.fully_qualified_name
columns = ["fk_col1"]
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@ resource "snowflake_table" "t" {
resource "snowflake_table_constraint" "pk" {
name = "%[4]s"
type = "PRIMARY KEY"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col1"]
enable = false
deferrable = false
Expand Down Expand Up @@ -209,7 +209,7 @@ resource "snowflake_table" "t" {
resource "snowflake_table_constraint" "unique" {
name="%s"
type= "UNIQUE"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col1"]
enforced = true
deferrable = false
Expand Down Expand Up @@ -388,7 +388,7 @@ resource "snowflake_table" "t" {
resource "snowflake_table_constraint" "unique" {
name = "%s"
type = "UNIQUE"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col1"]
}
`, n, databaseName, schemaName, n)
Expand Down Expand Up @@ -422,17 +422,17 @@ func tableConstraintEmptyForeignKeyProperties(name string, databaseName string,
name = "%[3]s"
database = "%[1]s"
schema = "%[2]s"
column {
name = "col1"
type = "NUMBER(38,0)"
}
}
resource "snowflake_table_constraint" "unique" {
name = "%[3]s"
type = "FOREIGN KEY"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col1"]
foreign_key_properties {
}
Expand All @@ -446,22 +446,22 @@ func tableConstraintForeignKeyProperties(name string, databaseName string, schem
name = "%[3]s"
database = "%[1]s"
schema = "%[2]s"
column {
name = "col1"
type = "NUMBER(38,0)"
}
}
resource "snowflake_table_constraint" "unique" {
name = "%[3]s"
type = "FOREIGN KEY"
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
columns = ["col1"]
foreign_key_properties {
references {
columns = ["col1"]
table_id = snowflake_table.t.qualified_name
table_id = snowflake_table.t.fully_qualified_name
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/resources/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ func GetReadUserFunc(withExternalChangesMarking bool) schema.ReadContextFunc {
}
return diag.FromErr(err)
}
if err := d.Set(FullyQualifiedNameAttributeName, id.FullyQualifiedName()); err != nil {
userParameters, err := client.Users.ShowParameters(ctx, id)
if err != nil {
return diag.FromErr(err)
}

userParameters, err := client.Users.ShowParameters(ctx, id)
if err != nil {
if err := d.Set(FullyQualifiedNameAttributeName, id.FullyQualifiedName()); err != nil {
return diag.FromErr(err)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/resources/user_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestAcc_User(t *testing.T) {
prefix := acc.TestClient().Ids.Alpha()
prefix2 := acc.TestClient().Ids.Alpha()
id := sdk.NewAccountObjectIdentifier(prefix)
id2 := sdk.NewAccountObjectIdentifier(prefix)
id2 := sdk.NewAccountObjectIdentifier(prefix2)

comment := random.Comment()
newComment := random.Comment()
Expand Down Expand Up @@ -238,8 +238,9 @@ resource "snowflake_user" "w" {
default_namespace="bar.baz"
}
`
s = fmt.Sprintf(s, prefix, prefix)
log.Printf("[DEBUG] s2 %s", s)
return fmt.Sprintf(s, prefix, prefix)
return s
}

// TestAcc_User_issue2058 proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2058 issue.
Expand Down

0 comments on commit fc97d84

Please sign in to comment.