Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: clarify provider documentation #739

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify that these fields are set. If not... it's an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a little time to understand that EnvDefaultFunc sets the value from env var 😅

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{})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configure is at later stage that returns the error. (Because now schema passes).

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
Loading