Skip to content

Commit 55da61e

Browse files
authored
feat(resource_folder): add retryable validation of parent_folder_uid existence (#2041)
Signed-off-by: Paulo Dias <[email protected]>
1 parent 043857c commit 55da61e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

internal/resources/grafana/resource_folder.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"regexp"
77
"strconv"
8+
"time"
89

910
goapi "github.com/grafana/grafana-openapi-client-go/client"
1011
"github.com/grafana/grafana-openapi-client-go/client/folders"
@@ -13,6 +14,7 @@ import (
1314

1415
"github.com/grafana/terraform-provider-grafana/v3/internal/common"
1516
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1618
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1719
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1820
)
@@ -98,7 +100,19 @@ func CreateFolder(ctx context.Context, d *schema.ResourceData, meta interface{})
98100
}
99101

100102
if parentUID, ok := d.GetOk("parent_folder_uid"); ok {
101-
body.ParentUID = parentUID.(string)
103+
err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
104+
parentFolder, err := GetFolderByIDorUID(client.Folders, parentUID.(string))
105+
if err != nil {
106+
return retry.RetryableError(err)
107+
}
108+
109+
body.ParentUID = parentFolder.UID
110+
return nil
111+
})
112+
113+
if err != nil {
114+
return diag.Errorf("failed to find parent folder '%s': %s", parentUID, err)
115+
}
102116
}
103117

104118
resp, err := client.Folders.CreateFolder(&body)

0 commit comments

Comments
 (0)