Skip to content

Commit a0984cd

Browse files
chore: Propose additional debug logging (#2243)
1 parent 6b563ac commit a0984cd

File tree

7 files changed

+107
-13
lines changed

7 files changed

+107
-13
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ Some links that might help you:
132132
- **If you are an enterprise customer**, reach out to your account team. This helps us prioritize issues.
133133
- The [issues section](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues) might already have an issue addressing your question.
134134

135+
## Additional debug logs for `snowflake_grant_privileges_to_role` resource
136+
Set environment variable `SF_TF_ADDITIONAL_DEBUG_LOGGING` to a non-empty value. Additional logs will be visible with `sf-tf-additional-debug` prefix, e.g.:
137+
```text
138+
2023/12/08 12:58:22.497078 sf-tf-additional-debug [DEBUG] Creating new client from db
139+
```
140+
135141
## Contributing
136142

137143
Cf. [Contributing](./CONTRIBUTING.md).

pkg/internal/logging/debug_helpers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package logging
2+
3+
import (
4+
"io"
5+
"log"
6+
"os"
7+
)
8+
9+
func init() {
10+
additionalDebugLoggingEnabled = os.Getenv("SF_TF_ADDITIONAL_DEBUG_LOGGING") != ""
11+
DebugLogger = log.New(os.Stderr, "sf-tf-additional-debug ", log.LstdFlags|log.Lmsgprefix|log.LUTC|log.Lmicroseconds)
12+
if !additionalDebugLoggingEnabled {
13+
DebugLogger.SetOutput(io.Discard)
14+
}
15+
}
16+
17+
var (
18+
additionalDebugLoggingEnabled bool
19+
DebugLogger *log.Logger
20+
)

pkg/resources/grant_privileges_to_role.go

Lines changed: 57 additions & 1 deletion
Large diffs are not rendered by default.

pkg/resources/schema_acceptance_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import (
77
"strings"
88
"testing"
99

10-
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
11-
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
12-
"github.com/hashicorp/terraform-plugin-testing/terraform"
13-
1410
acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"
11+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
1512
"github.com/hashicorp/terraform-plugin-testing/config"
13+
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1614
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
15+
"github.com/hashicorp/terraform-plugin-testing/terraform"
1716
"github.com/hashicorp/terraform-plugin-testing/tfversion"
1817
)
1918

pkg/sdk/grants_impl.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package sdk
22

3-
import "context"
3+
import (
4+
"context"
5+
6+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/logging"
7+
)
48

59
var _ Grants = (*grants)(nil)
610

@@ -9,22 +13,26 @@ type grants struct {
913
}
1014

1115
func (v *grants) GrantPrivilegesToAccountRole(ctx context.Context, privileges *AccountRoleGrantPrivileges, on *AccountRoleGrantOn, role AccountObjectIdentifier, opts *GrantPrivilegesToAccountRoleOptions) error {
16+
logging.DebugLogger.Printf("[DEBUG] Grant privileges to account role")
1217
if opts == nil {
1318
opts = &GrantPrivilegesToAccountRoleOptions{}
1419
}
1520
opts.privileges = privileges
1621
opts.on = on
1722
opts.accountRole = role
23+
logging.DebugLogger.Printf("[DEBUG] Grant privileges to account role: opts %+v", opts)
1824
return validateAndExec(v.client, ctx, opts)
1925
}
2026

2127
func (v *grants) RevokePrivilegesFromAccountRole(ctx context.Context, privileges *AccountRoleGrantPrivileges, on *AccountRoleGrantOn, role AccountObjectIdentifier, opts *RevokePrivilegesFromAccountRoleOptions) error {
28+
logging.DebugLogger.Printf("[DEBUG] Revoke privileges from account role")
2229
if opts == nil {
2330
opts = &RevokePrivilegesFromAccountRoleOptions{}
2431
}
2532
opts.privileges = privileges
2633
opts.on = on
2734
opts.accountRole = role
35+
logging.DebugLogger.Printf("[DEBUG] Revoke privileges from account role: opts %+v", opts)
2836
return validateAndExec(v.client, ctx, opts)
2937
}
3038

@@ -76,14 +84,19 @@ func (v *grants) GrantOwnership(ctx context.Context, on OwnershipGrantOn, to Own
7684
}
7785

7886
func (v *grants) Show(ctx context.Context, opts *ShowGrantOptions) ([]Grant, error) {
87+
logging.DebugLogger.Printf("[DEBUG] Show grants")
7988
if opts == nil {
8089
opts = &ShowGrantOptions{}
8190
}
8291

92+
logging.DebugLogger.Printf("[DEBUG] Show grants: opts %+v", opts)
8393
dbRows, err := validateAndQuery[grantRow](v.client, ctx, opts)
94+
logging.DebugLogger.Printf("[DEBUG] Show grants: query finished err = %v", err)
8495
if err != nil {
8596
return nil, err
8697
}
98+
logging.DebugLogger.Printf("[DEBUG] Show grants: converting rows")
8799
resultList := convertRows[grantRow, Grant](dbRows)
100+
logging.DebugLogger.Printf("[DEBUG] Show grants: rows converted")
88101
return resultList, nil
89102
}

pkg/sdk/tables_dto.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ type TableExternalTableColumnRenameActionRequest struct {
508508
}
509509

510510
type TableExternalTableColumnDropActionRequest struct {
511-
Columns []string //required
511+
Columns []string // required
512512
IfExists *bool
513513
}
514514

pkg/sdk/tables_dto_generated.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,20 +673,20 @@ func (s *DropTableRequest) WithRestrict(restrict *bool) *DropTableRequest {
673673
}
674674

675675
func NewTableAddRowAccessPolicyRequest(
676-
RowAccessPolicy SchemaObjectIdentifier,
677-
On []string,
676+
rowAccessPolicy SchemaObjectIdentifier,
677+
on []string,
678678
) *TableAddRowAccessPolicyRequest {
679679
s := TableAddRowAccessPolicyRequest{}
680-
s.RowAccessPolicy = RowAccessPolicy
681-
s.On = On
680+
s.RowAccessPolicy = rowAccessPolicy
681+
s.On = on
682682
return &s
683683
}
684684

685685
func NewTableDropRowAccessPolicyRequest(
686-
RowAccessPolicy SchemaObjectIdentifier,
686+
rowAccessPolicy SchemaObjectIdentifier,
687687
) *TableDropRowAccessPolicyRequest {
688688
s := TableDropRowAccessPolicyRequest{}
689-
s.RowAccessPolicy = RowAccessPolicy
689+
s.RowAccessPolicy = rowAccessPolicy
690690
return &s
691691
}
692692

0 commit comments

Comments
 (0)