Skip to content

Commit ec84372

Browse files
chore: Adjust to 2025_07 BCR part 2 (snowflakedb#4174)
- Adjust granting privileges on a database during a share update. - Add related sections to the BCR migration guide. ## References https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_07 snowflakedb#4018
1 parent ce1f354 commit ec84372

File tree

6 files changed

+126
-6
lines changed

6 files changed

+126
-6
lines changed

MIGRATION_GUIDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ If the bundle is disabled, then the `generation` column is not present in Snowfl
136136

137137
No changes in the configuration are necessary.
138138

139+
### *(improvement)* Granting privileges on a database during share update
140+
141+
When updating the `accounts` field in the `share` resource, the provider creates a temporary database from the share. Before, it granted only the `USAGE` grant. Now, it also grants `REFERENCE_USAGE` because of the changes in the [2025_07](./SNOWFLAKE_BCR_MIGRATION_GUIDE.md#disallow-grant-reference_usage-on-a-database-if-grant-usage-isnt-set-first) bundle.
142+
143+
No changes in the configuration are necessary.
144+
139145
## v2.9.x ➞ v2.10.0
140146

141147
### *(improvement)* Features promoted to stable

SNOWFLAKE_BCR_MIGRATION_GUIDE.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,41 @@ and [grant_privileges_to_database_role](https://registry.terraform.io/providers/
4141

4242
Reference: [BCR-2114](https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_07/bcr-2114)
4343

44+
### New default column sizes for string and binary data types
45+
46+
Before this change, the default size was 16 MB for text and 8 MB for binary columns. With the new bundle, the defaults increase to 128 MB for text and 64 MB for binary columns.
47+
For now, the provider will continue to use the old default size - 16 MB for text and 8 MB for binary. We are planning to adjust even more datatypes because of a new `DATA_TYPE_ALIAS` column in information schema - read [related BCR](https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_07/bcr-2061). We'll comeback to this in the future.
48+
49+
The datatype precision and scale can be specified for columns in the provider.
50+
51+
Reference: [BCR-2118](https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_07/bcr-2118)
52+
53+
### Disallow setting date and time output formats to AUTO
54+
55+
Snowflake now does not allow setting a number of time output parameters to `AUTO` - see the reference for the exact list. The provider does not validate such values in related resources. If you are using the `AUTO` value, adjust your configurations.
56+
57+
Reference: [BCR-2115](https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_07/bcr-2115)
58+
59+
### Python telemetry library automatically installed
60+
61+
Snowflake automatically installs the `snowflake-telemetry-python` package when a function or procedure with a Python handler is created. Read more about packages policy in [Snowflake documentation](https://docs.snowflake.com/en/developer-guide/udf/python/packages-policy). Package policies are not yet supported in the provider.
62+
63+
Reference: [BCR-2120](https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_07/bcr-2120)
64+
65+
### Disallow GRANT REFERENCE_USAGE on a database if GRANT USAGE isn’t set first
66+
67+
After enabling this BCR, `GRANT USAGE` on a database must be granted before `GRANT REFERENCE_USAGE`. These operations can be combined like `GRANT USAGE, REFERENCE_USAGE`. You can manage these in Terraform with [grant_privileges_to_share](https://registry.terraform.io/providers/snowflakedb/snowflake/latest/docs/resources/grant_privileges_to_share). You may need to adjust your grant configurations.
68+
69+
Additionally, when updating the `accounts` field in the `share` resource, the provider creates a temporary database from the share. Before, it granted only the `USAGE` grant. Since [v2.11.0](./MIGRATION_GUIDE.md#improvement-granting-privileges-on-a-database-during-share-update), it also grants `REFERENCE_USAGE`. If you have trouble updating or creating the `share` resource, update the provider to this version.
70+
71+
Reference: [BCR-2136](https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_07/bcr-2136)
72+
73+
### Default schedule for data metric functions in views
74+
75+
Setting data metric functions in views is now optional. In the provider, the `data_metric_function` field must be set if `data_metric_schedule` is set. The provider will continue to require setting that field for now. We are treating this relaxation as a missing feature, and we'll adjust it in the future.
76+
77+
Reference: [BCR-2101](https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_07/bcr-2101)
78+
4479
### New `generation` column in output in SHOW WAREHOUSES
4580

4681
This bundle adds the `generation` column. The values in `resource_constraint` column remain the same. The provider has been adjusted in [v2.10.1](./MIGRATION_GUIDE.md#improvement-handling-show_output-in-warehouses).

pkg/resources/share.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ func setShareAccounts(ctx context.Context, client *sdk.Client, shareID sdk.Accou
126126
// USAGE can only be granted to one database - granting USAGE on the temp db here
127127
// conflicts (and errors) with having a database already shared (i.e. when you
128128
// already have a share and are just adding or removing accounts). Instead, use
129-
// REFERENCE_USAGE which is intended for multi-database sharing as per Snowflake
129+
// USAGE and REFERENCE_USAGE which is intended for multi-database sharing as per Snowflake
130130
// documentation here:
131131
// https://docs.snowflake.com/en/sql-reference/sql/grant-privilege-share.html#usage-notes
132132
// Note however that USAGE will be granted automatically on the temp db for the
133133
// case where the main db doesn't already exist, so it will need to be revoked
134134
// before deleting the temp db. Where USAGE hasn't been already granted it is not
135135
// an error to revoke it, so it's ok to just do the revoke every time.
136-
err = client.Grants.GrantPrivilegeToShare(ctx, []sdk.ObjectPrivilege{sdk.ObjectPrivilegeReferenceUsage}, &sdk.ShareGrantOn{
136+
err = client.Grants.GrantPrivilegeToShare(ctx, []sdk.ObjectPrivilege{sdk.ObjectPrivilegeUsage, sdk.ObjectPrivilegeReferenceUsage}, &sdk.ShareGrantOn{
137137
Database: tempDatabaseID,
138138
}, shareID)
139139
if err != nil {

pkg/sdk/testint/shares_integration_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func TestInt_SharesCreate(t *testing.T) {
7373
Comment: sdk.String("test comment"),
7474
})
7575
require.NoError(t, err)
76+
t.Cleanup(testClientHelper().Share.DropShareFunc(t, id))
7677
shares, err := client.Shares.Show(ctx, &sdk.ShowShareOptions{
7778
Like: &sdk.Like{
7879
Pattern: sdk.String(id.Name()),
@@ -85,8 +86,6 @@ func TestInt_SharesCreate(t *testing.T) {
8586
assert.Len(t, shares, 1)
8687
assert.Equal(t, id.Name(), shares[0].Name.Name())
8788
assert.Equal(t, "test comment", shares[0].Comment)
88-
89-
t.Cleanup(testClientHelper().Share.DropShareFunc(t, id))
9089
})
9190

9291
t.Run("test no options", func(t *testing.T) {
@@ -96,11 +95,10 @@ func TestInt_SharesCreate(t *testing.T) {
9695
Comment: sdk.String("test comment"),
9796
})
9897
require.NoError(t, err)
98+
t.Cleanup(testClientHelper().Share.DropShareFunc(t, id))
9999
shares, err := client.Shares.Show(ctx, nil)
100100
require.NoError(t, err)
101101
assert.GreaterOrEqual(t, len(shares), 1)
102-
103-
t.Cleanup(testClientHelper().Share.DropShareFunc(t, id))
104102
})
105103
}
106104

pkg/testacc/resource_share_acceptance_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
// TODO [SNOW-1284394]: Unskip the test
17+
// TODO [SNOW-1348347]: Add more tests or merge with other tests.
1718
func TestAcc_Share(t *testing.T) {
1819
t.Skip("second and third account must be set for Share acceptance tests")
1920

@@ -70,6 +71,32 @@ func TestAcc_Share(t *testing.T) {
7071
})
7172
}
7273

74+
// TODO [SNOW-1348347]: Add more tests or merge with other tests.
75+
func TestAcc_Share_basic(t *testing.T) {
76+
account2 := secondaryTestClient().Account.GetAccountIdentifier(t)
77+
78+
id := testClient().Ids.RandomAccountObjectIdentifier()
79+
80+
resource.Test(t, resource.TestCase{
81+
ProtoV6ProviderFactories: TestAccProtoV6ProviderFactories,
82+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
83+
tfversion.RequireAbove(tfversion.Version1_5_0),
84+
},
85+
CheckDestroy: CheckDestroy(t, resources.Share),
86+
Steps: []resource.TestStep{
87+
{
88+
Config: shareConfigOneAccount(id, "", account2.Name()),
89+
Check: resource.ComposeTestCheckFunc(
90+
resource.TestCheckResourceAttr("snowflake_share.test", "name", id.Name()),
91+
resource.TestCheckResourceAttr("snowflake_share.test", "fully_qualified_name", id.FullyQualifiedName()),
92+
resource.TestCheckResourceAttr("snowflake_share.test", "accounts.#", "1"),
93+
resource.TestCheckResourceAttr("snowflake_share.test", "accounts.0", account2.Name()),
94+
),
95+
},
96+
},
97+
})
98+
}
99+
73100
func TestAcc_Share_validateAccounts(t *testing.T) {
74101
id := testClient().Ids.RandomAccountObjectIdentifier()
75102

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//go:build account_level_tests
2+
3+
package testacc
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
10+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config/providermodel"
11+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/testprofiles"
12+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources"
13+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
14+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
15+
"github.com/hashicorp/terraform-plugin-testing/tfversion"
16+
)
17+
18+
func TestAcc_Share_2025_07(t *testing.T) {
19+
secondaryTestClient().BcrBundles.EnableBcrBundle(t, "2025_07")
20+
// NOTE: In this case, we swap the test client to the secondary test client from the TestAcc_Share_basic test.
21+
// We enable the BCR bundle on the secondary test client, and make a share to the primary test client.
22+
account2 := testClient().Account.GetAccountIdentifier(t)
23+
24+
id := secondaryTestClient().Ids.RandomAccountObjectIdentifier()
25+
26+
resource.Test(t, resource.TestCase{
27+
ProtoV6ProviderFactories: secondaryAccountProviderFactory,
28+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
29+
tfversion.RequireAbove(tfversion.Version1_5_0),
30+
},
31+
CheckDestroy: CheckDestroy(t, resources.Share),
32+
Steps: []resource.TestStep{
33+
{
34+
Config: shareConfigOneAccount(id, "", account2.Name()) + config.FromModels(t, providermodel.SnowflakeProvider().WithProfile(testprofiles.Secondary)),
35+
Check: resource.ComposeTestCheckFunc(
36+
resource.TestCheckResourceAttr("snowflake_share.test", "name", id.Name()),
37+
resource.TestCheckResourceAttr("snowflake_share.test", "fully_qualified_name", id.FullyQualifiedName()),
38+
resource.TestCheckResourceAttr("snowflake_share.test", "accounts.#", "1"),
39+
resource.TestCheckResourceAttr("snowflake_share.test", "accounts.0", account2.Name()),
40+
),
41+
},
42+
},
43+
})
44+
}
45+
46+
func shareConfigOneAccount(shareId sdk.AccountObjectIdentifier, comment string, account string) string {
47+
return fmt.Sprintf(`
48+
resource "snowflake_share" "test" {
49+
name = "%s"
50+
comment = "%s"
51+
accounts = ["%s"]
52+
}
53+
`, shareId.Name(), comment, account)
54+
}

0 commit comments

Comments
 (0)