|
6 | 6 | "github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
|
7 | 7 |
|
8 | 8 | datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
|
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
9 | 10 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
10 | 11 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
11 | 12 | )
|
@@ -43,30 +44,34 @@ func dataSourceDatadogDashboardRead(d *schema.ResourceData, meta interface{}) er
|
43 | 44 | datadogClientV1 := providerConf.DatadogClientV1
|
44 | 45 | authV1 := providerConf.AuthV1
|
45 | 46 |
|
46 |
| - dashResponse, _, err := datadogClientV1.DashboardsApi.ListDashboards(authV1).Execute() |
47 |
| - |
48 |
| - if err != nil { |
49 |
| - return utils.TranslateClientError(err, "error querying dashboard") |
50 |
| - } |
| 47 | + return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { |
| 48 | + dashResponse, httpresp, err := datadogClientV1.DashboardsApi.ListDashboards(authV1).Execute() |
| 49 | + if err != nil { |
| 50 | + if httpresp != nil && httpresp.StatusCode == 504 { |
| 51 | + return resource.RetryableError(utils.TranslateClientError(err, "error querying dashboard, retrying")) |
| 52 | + } |
| 53 | + return resource.NonRetryableError(utils.TranslateClientError(err, "error querying dashboard")) |
| 54 | + } |
51 | 55 |
|
52 |
| - searchedName := d.Get("name") |
53 |
| - var foundDashes []datadogV1.DashboardSummaryDefinition |
| 56 | + searchedName := d.Get("name") |
| 57 | + var foundDashes []datadogV1.DashboardSummaryDefinition |
54 | 58 |
|
55 |
| - for _, dash := range dashResponse.GetDashboards() { |
56 |
| - if dash.GetTitle() == searchedName { |
57 |
| - foundDashes = append(foundDashes, dash) |
| 59 | + for _, dash := range dashResponse.GetDashboards() { |
| 60 | + if dash.GetTitle() == searchedName { |
| 61 | + foundDashes = append(foundDashes, dash) |
| 62 | + } |
58 | 63 | }
|
59 |
| - } |
60 | 64 |
|
61 |
| - if len(foundDashes) == 0 { |
62 |
| - return fmt.Errorf("Couldn't find a dashboard named %s", searchedName) |
63 |
| - } else if len(foundDashes) > 1 { |
64 |
| - return fmt.Errorf("%s returned more than one dashboard", searchedName) |
65 |
| - } |
| 65 | + if len(foundDashes) == 0 { |
| 66 | + return resource.NonRetryableError(fmt.Errorf("Couldn't find a dashboard named %s", searchedName)) |
| 67 | + } else if len(foundDashes) > 1 { |
| 68 | + return resource.NonRetryableError(fmt.Errorf("%s returned more than one dashboard", searchedName)) |
| 69 | + } |
66 | 70 |
|
67 |
| - d.SetId(foundDashes[0].GetId()) |
68 |
| - d.Set("url", foundDashes[0].GetUrl()) |
69 |
| - d.Set("title", foundDashes[0].GetTitle()) |
| 71 | + d.SetId(foundDashes[0].GetId()) |
| 72 | + d.Set("url", foundDashes[0].GetUrl()) |
| 73 | + d.Set("title", foundDashes[0].GetTitle()) |
70 | 74 |
|
71 |
| - return nil |
| 75 | + return nil |
| 76 | + }) |
72 | 77 | }
|
0 commit comments