@@ -91,7 +91,7 @@ This resource requires Grafana 9.1.0 or later.
91
91
"grafana_notification_policy" ,
92
92
orgResourceIDString ("anyString" ),
93
93
schema ,
94
- ).WithLister (listerFunction (listNotificationPolicies ))
94
+ ).WithLister (listerFunctionOrgResource (listNotificationPolicies ))
95
95
}
96
96
97
97
// The maximum depth of policy tree that the provider supports, as Terraform does not allow for infinitely recursive schemas.
@@ -191,35 +191,26 @@ func policySchema(depth uint) *schema.Resource {
191
191
return resource
192
192
}
193
193
194
- func listNotificationPolicies (ctx context.Context , client * goapi.GrafanaHTTPAPI , data * ListerData ) ([]string , error ) {
195
- orgIDs , err := data .OrgIDs (client )
196
- if err != nil {
197
- return nil , err
198
- }
199
-
194
+ func listNotificationPolicies (ctx context.Context , client * goapi.GrafanaHTTPAPI , orgID int64 ) ([]string , error ) {
200
195
var ids []string
201
- for _ , orgID := range orgIDs {
202
- client = client .Clone ().WithOrgID (orgID )
203
-
204
- // Retry if the API returns 500 because it may be that the alertmanager is not ready in the org yet.
205
- // The alertmanager is provisioned asynchronously when the org is created.
206
- if err := retry .RetryContext (ctx , 2 * time .Minute , func () * retry.RetryError {
207
- _ , err := client .Provisioning .GetPolicyTree ()
208
- if err != nil {
209
- if orgID > 1 && (err .(* runtime.APIError ).IsCode (500 ) || err .(* runtime.APIError ).IsCode (403 )) {
210
- return retry .RetryableError (err )
211
- }
212
- return retry .NonRetryableError (err )
196
+ // Retry if the API returns 500 because it may be that the alertmanager is not ready in the org yet.
197
+ // The alertmanager is provisioned asynchronously when the org is created.
198
+ if err := retry .RetryContext (ctx , 2 * time .Minute , func () * retry.RetryError {
199
+ _ , err := client .Provisioning .GetPolicyTree ()
200
+ if err != nil {
201
+ if orgID > 1 && (err .(* runtime.APIError ).IsCode (500 ) || err .(* runtime.APIError ).IsCode (403 )) {
202
+ return retry .RetryableError (err )
213
203
}
214
-
215
- return nil
216
- }); err != nil {
217
- return nil , err
204
+ return retry .NonRetryableError (err )
218
205
}
219
206
220
- ids = append (ids , MakeOrgResourceID (orgID , PolicySingletonID ))
207
+ return nil
208
+ }); err != nil {
209
+ return nil , err
221
210
}
222
211
212
+ ids = append (ids , MakeOrgResourceID (orgID , PolicySingletonID ))
213
+
223
214
return ids , nil
224
215
}
225
216
0 commit comments