11package grafana
22
33import (
4- "errors"
5- "fmt"
4+ "context"
65
6+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
77 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
88
99 onCallAPI "github.com/grafana/amixr-api-go-client"
@@ -15,7 +15,7 @@ func DataSourceOnCallAction() *schema.Resource {
1515**Note:** This data source is going to be deprecated, please use outgoing webhook data source instead.
1616* [HTTP API](https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/outgoing_webhooks/)
1717` ,
18- Read : dataSourceOnCallActionRead ,
18+ ReadContext : dataSourceOnCallActionRead ,
1919 DeprecationMessage : "This data source is going to be deprecated, please use outgoing webhook data source instead." ,
2020 Schema : map [string ]* schema.Schema {
2121 "name" : {
@@ -27,25 +27,22 @@ func DataSourceOnCallAction() *schema.Resource {
2727 }
2828}
2929
30- func dataSourceOnCallActionRead (d * schema.ResourceData , m interface {}) error {
30+ func dataSourceOnCallActionRead (ctx context. Context , d * schema.ResourceData , m interface {}) diag. Diagnostics {
3131 client := m .(* client ).onCallAPI
32- if client == nil {
33- return errors .New ("grafana OnCall api client is not configured" )
34- }
3532 options := & onCallAPI.ListCustomActionOptions {}
3633 nameData := d .Get ("name" ).(string )
3734
3835 options .Name = nameData
3936
4037 customActionsResponse , _ , err := client .CustomActions .ListCustomActions (options )
4138 if err != nil {
42- return err
39+ return diag . FromErr ( err )
4340 }
4441
4542 if len (customActionsResponse .CustomActions ) == 0 {
46- return fmt .Errorf ("couldn't find an action matching: %s" , options .Name )
43+ return diag .Errorf ("couldn't find an action matching: %s" , options .Name )
4744 } else if len (customActionsResponse .CustomActions ) != 1 {
48- return fmt .Errorf ("more than one action found matching: %s" , options .Name )
45+ return diag .Errorf ("more than one action found matching: %s" , options .Name )
4946 }
5047
5148 customAction := customActionsResponse .CustomActions [0 ]
0 commit comments