@@ -105,8 +105,8 @@ This resource requires Grafana 9.1.0 or later.
105
105
)
106
106
}
107
107
108
- // TODO: Fix lister
109
- // .WithLister(listerFunction(listContactPoints))
108
+ // TODO: Fix contact points lister. Terraform doesn't read any of the sensitive fields (or their container)
109
+ // It outputs an empty `email {}` block for example, which is not valid.
110
110
// func listContactPoints(ctx context.Context, client *goapi.GrafanaHTTPAPI, data *ListerData) ([]string, error) {
111
111
// orgIDs, err := data.OrgIDs(client)
112
112
// if err != nil {
@@ -117,14 +117,24 @@ This resource requires Grafana 9.1.0 or later.
117
117
// for _, orgID := range orgIDs {
118
118
// client = client.Clone().WithOrgID(orgID)
119
119
120
- // resp, err := client.Provisioning.GetContactpoints(provisioning.NewGetContactpointsParams())
121
- // if err != nil {
120
+ // // Retry if the API returns 500 because it may be that the alertmanager is not ready in the org yet.
121
+ // // The alertmanager is provisioned asynchronously when the org is created.
122
+ // if err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
123
+ // resp, err := client.Provisioning.GetContactpoints(provisioning.NewGetContactpointsParams())
124
+ // if err != nil {
125
+ // if orgID > 1 && (err.(*runtime.APIError).IsCode(500) || err.(*runtime.APIError).IsCode(403)) {
126
+ // return retry.RetryableError(err)
127
+ // }
128
+ // return retry.NonRetryableError(err)
129
+ // }
130
+
131
+ // for _, contactPoint := range resp.Payload {
132
+ // idMap[MakeOrgResourceID(orgID, contactPoint.Name)] = true
133
+ // }
134
+ // return nil
135
+ // }); err != nil {
122
136
// return nil, err
123
137
// }
124
-
125
- // for _, contactPoint := range resp.Payload {
126
- // idMap[MakeOrgResourceID(orgID, contactPoint.Name)] = true
127
- // }
128
138
// }
129
139
130
140
// var ids []string
@@ -138,13 +148,16 @@ This resource requires Grafana 9.1.0 or later.
138
148
func readContactPoint (ctx context.Context , data * schema.ResourceData , meta interface {}) diag.Diagnostics {
139
149
client , orgID , name := OAPIClientFromExistingOrgResource (meta , data .Id ())
140
150
141
- // First, try to fetch the contact point by name.
142
- // If that fails, try to fetch it by the UID of its notifiers.
143
- resp , err := client .Provisioning .GetContactpoints (provisioning .NewGetContactpointsParams ().WithName (& name ))
151
+ resp , err := client .Provisioning .GetContactpoints (provisioning .NewGetContactpointsParams ())
144
152
if err != nil {
145
153
return diag .FromErr (err )
146
154
}
147
- points := resp .Payload
155
+ var points []* models.EmbeddedContactPoint
156
+ for _ , p := range resp .Payload {
157
+ if p .Name == name {
158
+ points = append (points , p )
159
+ }
160
+ }
148
161
if len (points ) == 0 {
149
162
return common .WarnMissing ("contact point" , data )
150
163
}
0 commit comments