Skip to content

Commit

Permalink
add provider validators
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Nov 15, 2023
1 parent 6fd0ca9 commit 41b7e05
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import (
ds "terraform-provider-plural/internal/datasource"
r "terraform-provider-plural/internal/resource"

"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"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"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
client "github.com/pluralsh/console-client-go"
"github.com/pluralsh/plural-cli/pkg/console"
Expand Down Expand Up @@ -46,15 +49,31 @@ func (p *PluralProvider) Schema(_ context.Context, _ provider.SchemaRequest, res
"console_url": schema.StringAttribute{
MarkdownDescription: "Plural Console URL, i.e. `https://console.demo.onplural.sh`. Can be sourced from `PLURAL_CONSOLE_URL`.",
Optional: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("use_cli")),
stringvalidator.ExactlyOneOf(path.MatchRoot("use_cli")),
},
},
"access_token": schema.StringAttribute{
MarkdownDescription: "Plural Console access token. Can be sourced from `PLURAL_ACCESS_TOKEN`.",
Optional: true,
Sensitive: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("use_cli")),
stringvalidator.ExactlyOneOf(path.MatchRoot("use_cli")),
},
},
"use_cli": schema.BoolAttribute{
MarkdownDescription: "Use Plural CLI `plural cd login` command for authentication. Can be sourced from `PLURAL_USE_CLI`.",
Optional: true,
Validators: []validator.Bool{
boolvalidator.ConflictsWith(
path.MatchRoot("console_url"),
path.MatchRoot("access_token"),
),
boolvalidator.ExactlyOneOf(path.MatchRoot("console_url")),
boolvalidator.ExactlyOneOf(path.MatchRoot("access_token")),
},
},
},
}
Expand Down

0 comments on commit 41b7e05

Please sign in to comment.