From 7aafa050bb6749427881df7419486f959dc1af35 Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Fri, 15 Dec 2023 08:54:48 -0500 Subject: [PATCH 1/2] Remove validation in new provider framework config This validation was added here: https://github.com/grafana/terraform-provider-grafana/pull/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 --- internal/provider/configure_clients.go | 2 +- internal/provider/framework_provider.go | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/internal/provider/configure_clients.go b/internal/provider/configure_clients.go index 95acab76c..7772002a0 100644 --- a/internal/provider/configure_clients.go +++ b/internal/provider/configure_clients.go @@ -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 diff --git a/internal/provider/framework_provider.go b/internal/provider/framework_provider.go index 031d37169..9d7065e98 100644 --- a/internal/provider/framework_provider.go +++ b/internal/provider/framework_provider.go @@ -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 } From 70ffaa005a1de70ba716bc078b3b393f70bad498 Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Fri, 15 Dec 2023 08:57:03 -0500 Subject: [PATCH 2/2] Remove failing test. This validation is now done later --- internal/provider/legacy_provider_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/internal/provider/legacy_provider_test.go b/internal/provider/legacy_provider_test.go index 9d3549e3a..77070df9d 100644 --- a/internal/provider/legacy_provider_test.go +++ b/internal/provider/legacy_provider_test.go @@ -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{