Skip to content

Commit

Permalink
Remove validation in new provider framework config (#1235)
Browse files Browse the repository at this point in the history
* Remove validation in new provider framework config
This validation was added here: #1206
However, it's done too early and it prevents the cases where we create a second provider with auth from a dynamically created API key or service account

* Remove failing test. This validation is now done later
  • Loading branch information
julienduchesne authored Dec 15, 2023
1 parent 1dfd29a commit a8addd7
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 14 deletions.
2 changes: 1 addition & 1 deletion internal/provider/configure_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
func createClients(providerConfig frameworkProviderConfig) (*common.Client, error) {
var err error
c := &common.Client{}
if !providerConfig.Auth.IsNull() {
if !providerConfig.Auth.IsNull() && !providerConfig.URL.IsNull() {
c.GrafanaAPIURL, c.GrafanaAPIConfig, c.DeprecatedGrafanaAPI, err = createGrafanaClient(providerConfig)
if err != nil {
return nil, err
Expand Down
8 changes: 0 additions & 8 deletions internal/provider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ func (c *frameworkProviderConfig) SetDefaults() error {
})
}

// Validating here so that it's done for both provider versions (SDK and Plugin Framework)
if c.Auth.IsNull() && c.CloudAPIKey.IsNull() && c.SMAccessToken.IsNull() && c.OncallAccessToken.IsNull() {
return fmt.Errorf("at least one of the following attributes must be set: auth, cloud_api_key, sm_access_token, oncall_access_token")
}
if !c.Auth.IsNull() && c.URL.IsNull() || c.Auth.IsNull() && !c.URL.IsNull() {
return fmt.Errorf("both auth and url must be set")
}

return nil
}

Expand Down
5 changes: 0 additions & 5 deletions internal/provider/legacy_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func TestProviderConfigure(t *testing.T) {
expectedErr string
check func(t *testing.T, provider *schema.Provider)
}{
{
name: "no config",
env: map[string]string{},
expectedErr: "at least one of the following attributes must be set: auth, cloud_api_key, sm_access_token, oncall_access_token",
},
{
name: "grafana config from env",
env: map[string]string{
Expand Down

0 comments on commit a8addd7

Please sign in to comment.