Skip to content

Commit 92e2679

Browse files
author
Abdelkarim Boujida
committed
Some bug fixes
1 parent 29b852a commit 92e2679

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/hashicorp/terraform-plugin-docs v0.18.0
88
github.com/hashicorp/terraform-plugin-framework v1.6.1
99
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
10+
github.com/hashicorp/terraform-plugin-go v0.22.1
1011
github.com/hashicorp/terraform-plugin-log v0.9.0
1112
golang.org/x/net v0.22.0
1213
)
@@ -45,7 +46,6 @@ require (
4546
github.com/hashicorp/hc-install v0.6.3 // indirect
4647
github.com/hashicorp/terraform-exec v0.20.0 // indirect
4748
github.com/hashicorp/terraform-json v0.21.0 // indirect
48-
github.com/hashicorp/terraform-plugin-go v0.22.1 // indirect
4949
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
5050
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
5151
github.com/hashicorp/yamux v0.1.1 // indirect

internal/provider/resource_default_privileges.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1919
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
2020
"github.com/hashicorp/terraform-plugin-framework/types"
21+
"github.com/hashicorp/terraform-plugin-log/tflog"
2122
)
2223

2324
var (
@@ -381,14 +382,29 @@ func (r *defaultPriviligesResource) Delete(ctx context.Context, req resource.Del
381382
tx, err := db.BeginTx(ctx, nil)
382383
if err != nil {
383384
resp.Diagnostics.AddError(
384-
"Error creating role",
385+
"Error removing default privileges",
385386
"Unable to create transaction to the database, unexpected error: "+err.Error(),
386387
)
387388
return
388389
}
389390
defer tx.Rollback()
390391

391-
r.revokeAll(ctx, tx, owner, inSchema, objectType, role)
392+
err = r.revokeAll(ctx, tx, owner, inSchema, objectType, role)
393+
if err != nil {
394+
resp.Diagnostics.AddError(
395+
"Error removing default privileges",
396+
"Unexpected error: "+err.Error(),
397+
)
398+
return
399+
}
400+
401+
if err = tx.Commit(); err != nil {
402+
resp.Diagnostics.AddError(
403+
"Error rem]moving the default privileges",
404+
"Unable to commit the default privileges from '"+role+"' on database '"+database+"', unexpected error: "+err.Error(),
405+
)
406+
return
407+
}
392408
}
393409

394410
func (r *defaultPriviligesResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
@@ -410,6 +426,7 @@ func (r *defaultPriviligesResource) Configure(_ context.Context, req resource.Co
410426

411427
func (r *defaultPriviligesResource) revokeAll(ctx context.Context, tx *sql.Tx, owner string, inSchema string, objectType string, role string) error {
412428
sqlStatement := fmt.Sprintf("ALTER DEFAULT PRIVILEGES FOR ROLE %s %s REVOKE ALL ON %s FROM %s", owner, inSchema, objectType, role)
429+
tflog.Debug(ctx, "The SQL statement: "+sqlStatement)
413430

414431
_, err := tx.ExecContext(ctx, sqlStatement)
415432
return err

internal/provider/resource_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func (r *roleResource) readRole(ctx context.Context, role *roleResourceModel) er
313313
role.ConnectionLimit = types.Int64Value(connectionLimit)
314314

315315
if isValidUntil == "infinity" {
316-
role.IsValidUntil = NewCustomTimestampValue(isValidUntil)
316+
role.IsValidUntil = NewCustomTimestampNull()
317317
} else {
318318
isValidUntilTime, _ := time.Parse(time.RFC3339, isValidUntil)
319319
utcLocation, _ := time.LoadLocation("UTC")

0 commit comments

Comments
 (0)