Skip to content
Open
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
5 changes: 1 addition & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ provider "tlspc" {
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `apikey` (String) API Key

### Optional

- `apikey` (String) API Key. Required unless specified by setting the environment variable `TLSPC_APIKEY`
- `endpoint` (String) TLSPC API Endpoint
16 changes: 13 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/function"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -55,9 +56,8 @@ We recommend that you create a custom user with the [permissions required](https
Description: "Provider for the Venafi TLS Protect Cloud Platform",
Attributes: map[string]schema.Attribute{
"apikey": schema.StringAttribute{
MarkdownDescription: "API Key",
Optional: false,
Required: true,
MarkdownDescription: "API Key. Required unless specified by setting the environment variable `TLSPC_APIKEY`",
Optional: true,
},
"endpoint": schema.StringAttribute{
MarkdownDescription: "TLSPC API Endpoint",
Expand All @@ -81,9 +81,19 @@ func (p *tlspcProvider) Configure(ctx context.Context, req provider.ConfigureReq
if !config.ApiKey.IsNull() {
apikey = config.ApiKey.ValueString()
}
if apikey == "" {
resp.Diagnostics.AddAttributeError(
path.Root("apikey"),
"API Key not provided",
"The provider cannot create the TLSPC API client as the API Key has not been provided",
)
}
if !config.Endpoint.IsNull() {
endpoint = config.Endpoint.ValueString()
}
if resp.Diagnostics.HasError() {
return
}

client, _ := tlspc.NewClient(apikey, endpoint, p.version)

Expand Down
Loading