Skip to content

Commit

Permalink
item update behaviour to ignore manual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
odise committed Oct 25, 2024
1 parent b942ecf commit bc21987
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions internal/provider/onepassword_item_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func (r *OnePasswordItemResource) Schema(ctx context.Context, req resource.Schem
"url": schema.StringAttribute{
MarkdownDescription: urlDescription,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
ValueModifier(),
},
},
"hostname": schema.StringAttribute{
MarkdownDescription: dbHostnameDescription,
Expand Down Expand Up @@ -207,6 +211,10 @@ func (r *OnePasswordItemResource) Schema(ctx context.Context, req resource.Schem
"username": schema.StringAttribute{
MarkdownDescription: usernameDescription,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
ValueModifier(),
},
},
"password": schema.StringAttribute{
MarkdownDescription: passwordDescription,
Expand Down Expand Up @@ -464,7 +472,10 @@ func itemToData(ctx context.Context, item *op.Item, data *OnePasswordItemResourc

for _, u := range item.URLs {
if u.Primary {
data.URL = setStringValue(u.URL)
// we need to keep "" and can't set to null here because otherwise:
// When applying changes to onepassword_item.test-database, provider produced an
// unexpected new value: .username: was cty.StringVal(""), but now null.
data.URL = types.StringValue(u.URL)
}
}

Expand Down Expand Up @@ -580,7 +591,10 @@ func itemToData(ctx context.Context, item *op.Item, data *OnePasswordItemResourc
for _, f := range item.Fields {
switch f.Purpose {
case op.FieldPurposeUsername:
data.Username = setStringValue(f.Value)
// we need to keep "" and can't set to null here because otherwise:
// When applying changes to onepassword_item.test-database, provider produced an
// unexpected new value: .username: was cty.StringVal(""), but now null.
data.Username = types.StringValue(f.Value)
case op.FieldPurposePassword:
data.Password = setStringValue(f.Value)
case op.FieldPurposeNotes:
Expand All @@ -604,6 +618,10 @@ func itemToData(ctx context.Context, item *op.Item, data *OnePasswordItemResourc
}
}
}
// we set username to be a known null value just in case it hasn't been set above
if data.Username.IsUnknown() {
data.Username = types.StringNull()
}

if item.Category == op.SecureNote && data.Password.IsUnknown() {
data.Password = types.StringNull()
Expand Down

0 comments on commit bc21987

Please sign in to comment.