From 5e3e192454a91697b8c350205c3f4413b48e2b10 Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Wed, 20 Mar 2024 10:30:14 -0400 Subject: [PATCH] Add validation for update and delete too. These can make tests panic --- internal/resources/grafana/resources.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/resources/grafana/resources.go b/internal/resources/grafana/resources.go index 12b57b3d0..216d7ccb7 100644 --- a/internal/resources/grafana/resources.go +++ b/internal/resources/grafana/resources.go @@ -27,8 +27,10 @@ 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 { @@ -36,6 +38,22 @@ func addValidation(resources map[string]*schema.Resource) map[string]*schema.Res } 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 {