-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just like #1393 - Makes the resource functions private (exposed via a single map attribute) rather than each resource individually - Puts the client validation in the SLO package
- Loading branch information
1 parent
226d3f5
commit 03a6644
Showing
4 changed files
with
47 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package slo | ||
|
||
import ( | ||
"context" | ||
|
||
slo "github.com/grafana/slo-openapi-client/go" | ||
"github.com/grafana/terraform-provider-grafana/internal/common" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
type crudWithClientFunc func(ctx context.Context, d *schema.ResourceData, client *slo.APIClient) diag.Diagnostics | ||
|
||
func withClient[T schema.CreateContextFunc | schema.UpdateContextFunc | schema.ReadContextFunc | schema.DeleteContextFunc](f crudWithClientFunc) T { | ||
return func(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*common.Client).SLOClient | ||
if client == nil { | ||
return diag.Errorf("the SLO API client is required for this resource. Set the url and auth provider attributes") | ||
} | ||
return f(ctx, d, client) | ||
} | ||
} | ||
|
||
var DatasourcesMap = map[string]*schema.Resource{ | ||
"grafana_slos": datasourceSlo(), | ||
} | ||
|
||
var ResourcesMap = map[string]*schema.Resource{ | ||
"grafana_slo": resourceSlo(), | ||
} |