Skip to content

Commit 730db50

Browse files
error out if Grafana provider is not correctly configured for LBAC data source (#2162)
1 parent faae439 commit 730db50

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

internal/resources/grafana/resource_data_source_config_lbac_rules.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,31 @@ This resource requires Grafana >=11.5.0.
8383
}
8484
}
8585

86-
func (r *resourceDataSourceConfigLBACRules) Configure(ctx context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) {
87-
if req.ProviderData == nil {
86+
func (r *resourceDataSourceConfigLBACRules) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
87+
// Check if the provider data is nil or if the client is already set
88+
if req.ProviderData == nil || r.client != nil {
8889
return
8990
}
90-
r.client = req.ProviderData.(*common.Client)
91+
92+
client, ok := req.ProviderData.(*common.Client)
93+
if !ok {
94+
resp.Diagnostics.AddError(
95+
"Unexpected resource configure type",
96+
fmt.Sprintf("Expected *common.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
97+
)
98+
return
99+
}
100+
101+
// Check if the client is correctly configured
102+
if client.GrafanaAPI == nil {
103+
resp.Diagnostics.AddError(
104+
"The Grafana Provider is missing a configuration for the Grafana API.",
105+
"Please ensure that URL and auth are set in the provider configuration.",
106+
)
107+
return
108+
}
109+
110+
r.client = client
91111
}
92112

93113
// Add this helper function to handle the common update logic

0 commit comments

Comments
 (0)