Skip to content

Commit

Permalink
Add validation for update and delete too. These can make tests panic
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduchesne committed Mar 20, 2024
1 parent 513d516 commit 5e3e192
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion internal/resources/grafana/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,33 @@ func grafanaOrgIDResourceValidation(d *schema.ResourceData, m interface{}) error

func addValidation(resources map[string]*schema.Resource) map[string]*schema.Resource {
for _, r := range resources {
readFn := r.ReadContext
createFn := r.CreateContext
readFn := r.ReadContext
updateFn := r.UpdateContext
deleteFn := r.DeleteContext

r.ReadContext = func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
if err := grafanaClientResourceValidation(d, m); err != nil {
return diag.FromErr(err)
}
return readFn(ctx, d, m)
}
if updateFn != nil {
r.UpdateContext = func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
if err := grafanaClientResourceValidation(d, m); err != nil {
return diag.FromErr(err)
}
return updateFn(ctx, d, m)
}
}
if deleteFn != nil {
r.DeleteContext = func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
if err := grafanaClientResourceValidation(d, m); err != nil {
return diag.FromErr(err)
}
return deleteFn(ctx, d, m)
}
}
if createFn != nil {
r.CreateContext = func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
if err := grafanaClientResourceValidation(d, m); err != nil {
Expand Down

0 comments on commit 5e3e192

Please sign in to comment.