Skip to content

Commit

Permalink
Feat: clarify provider documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Nov 1, 2023
1 parent b95b5dd commit f36bd08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions env0/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ func Provider(version string) plugin.ProviderFunc {
},
"api_key": {
Type: schema.TypeString,
Description: "env0 API key. This can also be set via the ENV0_API_KEY environment variable.",
Description: "env0 API key. Instead of this field, it can also be set via the ENV0_API_KEY environment variable.",
DefaultFunc: schema.EnvDefaultFunc(apiKeyEnv, nil),
Required: true,
Optional: true,
Sensitive: true,
},
"api_secret": {
Type: schema.TypeString,
Description: "env0 API secret. This can also be set via the ENV0_API_SECRET environment variable.",
Description: "env0 API secret. Instead of this field, it can also be set via the ENV0_API_SECRET environment variable.",
DefaultFunc: schema.EnvDefaultFunc(apiSecretEnv, nil),
Required: true,
Optional: true,
Sensitive: true,
},
"organization_id": {
Expand Down Expand Up @@ -195,9 +195,19 @@ func configureProvider(version string, p *schema.Provider) schema.ConfigureConte
return false
})

apiKey, ok := d.GetOk("api_key")
if !ok {
return nil, diag.Diagnostics{diag.Diagnostic{Severity: diag.Error, Detail: `The argument "api_key" is required, but no definition was found.`}}
}

apiSecret, ok := d.GetOk("api_secret")
if !ok {
return nil, diag.Diagnostics{diag.Diagnostic{Severity: diag.Error, Detail: `The argument "api_secret" is required, but no definition was found.`}}
}

httpClient, err := http.NewHttpClient(http.HttpClientConfig{
ApiKey: d.Get("api_key").(string),
ApiSecret: d.Get("api_secret").(string),
ApiKey: apiKey.(string),
ApiSecret: apiSecret.(string),
ApiEndpoint: d.Get("api_endpoint").(string),
UserAgent: userAgent,
RestClient: restyClient,
Expand Down
4 changes: 2 additions & 2 deletions env0/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ func testMissingEnvVar(t *testing.T, envVars map[string]string, expectedKey stri
defer os.Setenv(key, "")
}

diags := Provider("TEST")().Validate(&terraform.ResourceConfig{})
diags := Provider("TEST")().Configure(context.Background(), &terraform.ResourceConfig{})
testExpectedProviderError(t, diags, expectedKey)
}

func testMissingConfig(t *testing.T, config map[string]interface{}, expectedKey string) {
diags := Provider("TEST")().Validate(terraform.NewResourceConfigRaw(config))
diags := Provider("TEST")().Configure(context.Background(), terraform.NewResourceConfigRaw(config))
testExpectedProviderError(t, diags, expectedKey)
}

Expand Down

0 comments on commit f36bd08

Please sign in to comment.