Skip to content

Commit 6fba88b

Browse files
authored
Merge pull request #265 from 1Password/jill/update-auth-params
Update auth params
2 parents 4919b58 + 03aa1a1 commit 6fba88b

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

examples/provider/provider.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
provider "onepassword" {
2-
url = "http://localhost:8080"
3-
token = "CONNECT_TOKEN"
2+
connect_url = "http://localhost:8080"
3+
connect_token = "CONNECT_TOKEN"
44
service_account_token = "SERVICE_ACCOUNT_TOKEN"
5-
account = "ACCOUNT_ID_OR_SIGN_IN_ADDRESS"
5+
account = "ACCOUNT_NAME"
66
}

internal/onepassword/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ func NewClient(ctx context.Context, config ClientConfig) (Client, error) {
4141
ProviderUserAgent: config.ProviderUserAgent,
4242
}), nil
4343
}
44-
return nil, errors.New("Invalid provider configuration. Either Connect credentials (\"token\" and \"url\") or Service Account (\"service_account_token\" or \"account\") credentials should be set.")
44+
return nil, errors.New("Invalid provider configuration. Either Connect credentials (\"connect_token\" and \"connect_url\") or Service Account (\"service_account_token\") or \"account\" should be set.")
4545
}

internal/provider/provider.go

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import (
55
"fmt"
66
"os"
77

8+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
89
"github.com/hashicorp/terraform-plugin-framework/datasource"
910
"github.com/hashicorp/terraform-plugin-framework/function"
11+
"github.com/hashicorp/terraform-plugin-framework/path"
1012
"github.com/hashicorp/terraform-plugin-framework/provider"
1113
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
1214
"github.com/hashicorp/terraform-plugin-framework/resource"
15+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1316
"github.com/hashicorp/terraform-plugin-framework/types"
1417

1518
"github.com/1Password/terraform-provider-onepassword/v2/internal/onepassword"
@@ -29,10 +32,13 @@ type OnePasswordProvider struct {
2932

3033
// OnePasswordProviderModel describes the provider data model.
3134
type OnePasswordProviderModel struct {
32-
ConnectHost types.String `tfsdk:"url"`
33-
ConnectToken types.String `tfsdk:"token"`
35+
ConnectHost types.String `tfsdk:"connect_url"`
36+
ConnectToken types.String `tfsdk:"connect_token"`
3437
ServiceAccountToken types.String `tfsdk:"service_account_token"`
3538
Account types.String `tfsdk:"account"`
39+
// Old field names - these are deprecated and will be removed in a future version.
40+
ConnectHostOld types.String `tfsdk:"url"`
41+
ConnectTokenOld types.String `tfsdk:"token"`
3642
}
3743

3844
func (p *OnePasswordProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
@@ -43,15 +49,40 @@ func (p *OnePasswordProvider) Metadata(ctx context.Context, req provider.Metadat
4349
func (p *OnePasswordProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
4450
resp.Schema = schema.Schema{
4551
Attributes: map[string]schema.Attribute{
46-
"url": schema.StringAttribute{
52+
"connect_url": schema.StringAttribute{
4753
MarkdownDescription: "The HTTP(S) URL where your 1Password Connect server can be found. Can also be sourced `OP_CONNECT_HOST` environment variable. Provider will use 1Password Connect server if set.",
4854
Optional: true,
4955
},
50-
"token": schema.StringAttribute{
56+
"connect_token": schema.StringAttribute{
5157
MarkdownDescription: "A valid token for your 1Password Connect server. Can also be sourced from `OP_CONNECT_TOKEN` environment variable. Provider will use 1Password Connect server if set.",
5258
Optional: true,
5359
Sensitive: true,
5460
},
61+
"url": schema.StringAttribute{
62+
MarkdownDescription: "The HTTP(S) URL where your 1Password Connect server can be found. Can also be sourced `OP_CONNECT_HOST` environment variable. Provider will use 1Password Connect server if set. Deprecated: Use `connect_url` instead.",
63+
Optional: true,
64+
Validators: []validator.String{
65+
stringvalidator.ConflictsWith(
66+
path.Expressions{
67+
path.MatchRoot("connect_url"),
68+
}...,
69+
),
70+
},
71+
DeprecationMessage: "The \"url\" field is deprecated and will be removed in a future version. Use \"connect_url\" instead.",
72+
},
73+
"token": schema.StringAttribute{
74+
MarkdownDescription: "A valid token for your 1Password Connect server. Can also be sourced from `OP_CONNECT_TOKEN` environment variable. Provider will use 1Password Connect server if set. Deprecated: Use `connect_token` instead.",
75+
Optional: true,
76+
Sensitive: true,
77+
Validators: []validator.String{
78+
stringvalidator.ConflictsWith(
79+
path.Expressions{
80+
path.MatchRoot("connect_token"),
81+
}...,
82+
),
83+
},
84+
DeprecationMessage: "The \"token\" field is deprecated and will be removed in a future version. Use \"connect_token\" instead.",
85+
},
5586
"service_account_token": schema.StringAttribute{
5687
MarkdownDescription: "A valid 1Password service account token. Can also be sourced from `OP_SERVICE_ACCOUNT_TOKEN` environment variable.",
5788
Optional: true,
@@ -88,6 +119,15 @@ func (p *OnePasswordProvider) Configure(ctx context.Context, req provider.Config
88119
if !config.ConnectToken.IsNull() {
89120
connectToken = config.ConnectToken.ValueString()
90121
}
122+
123+
// Old field names - these are deprecated and will be removed in a future version.
124+
if !config.ConnectHostOld.IsNull() {
125+
connectHost = config.ConnectHostOld.ValueString()
126+
}
127+
if !config.ConnectTokenOld.IsNull() {
128+
connectToken = config.ConnectTokenOld.ValueString()
129+
}
130+
91131
if !config.ServiceAccountToken.IsNull() {
92132
serviceAccountToken = config.ServiceAccountToken.ValueString()
93133
}
@@ -100,8 +140,6 @@ func (p *OnePasswordProvider) Configure(ctx context.Context, req provider.Config
100140
// the other one is prompted for, but Terraform then forgets the value for the one that
101141
// is defined in the code. This confusing user-experience can be avoided by handling the
102142
// requirement of one of the attributes manually.
103-
//
104-
// TODO: Investigate if wrapping this as a (framework) validator can be a better fit.
105143
if serviceAccountToken != "" || account != "" {
106144
if connectToken != "" || connectHost != "" {
107145
resp.Diagnostics.AddError("Config conflict", "Either Connect credentials (\"connect_token\" and \"connect_url\") or \"service_account_token\" or \"account\" can be set. Multiple are set. Only one credential must be set.")

internal/provider/provider_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServe
1818
func testAccProviderConfig(url string) string {
1919
return fmt.Sprintf(`
2020
provider "onepassword" {
21-
url = "%s"
22-
token = "<PASSWORD>"
21+
connect_url = "%s"
22+
connect_token = "<PASSWORD>"
2323
}`, url)
2424
}

test/e2e/item_resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ func TestAccItemResourceTags(t *testing.T) {
554554
tags []string
555555
}{
556556
{"CREATE_ITEM_WITH_2_TAGS", []string{"firstTestTag", "secondTestTag"}},
557-
// {"ADD_3RD_TAG", []string{"firstTestTag", "secondTestTag", "thirdTestTag"}},
558-
// {"REMOVE_2_TAGS", []string{"firstTestTag"}},
557+
{"ADD_3RD_TAG", []string{"firstTestTag", "secondTestTag", "thirdTestTag"}},
558+
{"REMOVE_2_TAGS", []string{"firstTestTag"}},
559559
}
560560

561561
testVaultID := vault.GetTestVaultID(t)

0 commit comments

Comments
 (0)