Skip to content

Commit

Permalink
fix(list_item): fix schema mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Feb 5, 2025
1 parent 169d4f5 commit 7944314
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/services/list_item/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ListItemResultEnvelope struct {
type ListItemModel struct {
ListID types.String `tfsdk:"list_id" path:"list_id,required"`
AccountID types.String `tfsdk:"account_id" path:"account_id,optional"`
ItemID types.String `tfsdk:"item_id" path:"item_id,computed"`
ID types.String `tfsdk:"id" path:"item_id,computed"`
ASN types.Int64 `tfsdk:"asn" json:"asn,optional"`
Comment types.String `tfsdk:"comment" json:"comment,optional"`
IP types.String `tfsdk:"ip" json:"ip,optional"`
Expand Down
8 changes: 4 additions & 4 deletions internal/services/list_item/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ func (r *ListItemResource) Create(ctx context.Context, req resource.CreateReques
}
findListItem, _ := io.ReadAll(findItemRes.Body)
itemID := gjson.Get(string(findListItem), "result.0.id")
data.ItemID = types.StringValue(itemID.String())
data.ID = types.StringValue(itemID.String())

env := ListItemResultEnvelope{*data}
listItemRes := new(http.Response)
_, err = r.client.Rules.Lists.Items.Get(
ctx,
data.AccountID.ValueString(),
data.ListID.ValueString(),
data.ItemID.ValueString(),
data.ID.ValueString(),
option.WithResponseBodyInto(&listItemRes),
option.WithMiddleware(logging.Middleware(ctx)),
)
Expand Down Expand Up @@ -207,7 +207,7 @@ func (r *ListItemResource) Read(ctx context.Context, req resource.ReadRequest, r
ctx,
data.AccountID.ValueString(),
data.ListID.ValueString(),
data.ItemID.ValueString(),
data.ID.ValueString(),
option.WithResponseBodyInto(&res),
option.WithMiddleware(logging.Middleware(ctx)),
)
Expand Down Expand Up @@ -242,7 +242,7 @@ func (r *ListItemResource) Delete(ctx context.Context, req resource.DeleteReques

deletePayload := bodyDeletePayload{
Items: []bodyDeleteItems{{
ID: data.ItemID.ValueString(),
ID: data.ID.ValueString(),
}},
}
deleteBody, _ := json.Marshal(deletePayload)
Expand Down
8 changes: 2 additions & 6 deletions internal/services/list_item/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ResourceSchema(ctx context.Context) schema.Schema {
Optional: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
},
"item_id": schema.StringAttribute{
"id": schema.StringAttribute{
Description: "The unique ID of the item in the List.",
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
Expand All @@ -42,16 +42,12 @@ func ResourceSchema(ctx context.Context) schema.Schema {
},
"comment": schema.StringAttribute{
Description: "An informative summary of the list item.",
Computed: true,
Optional: true,
},
"created_on": schema.StringAttribute{
Description: "The RFC 3339 timestamp of when the item was created.",
Computed: true,
},
"id": schema.StringAttribute{
Description: "The unique ID of the list.",
Computed: true,
},
"modified_on": schema.StringAttribute{
Description: "The RFC 3339 timestamp of when the item was last modified.",
Computed: true,
Expand Down

0 comments on commit 7944314

Please sign in to comment.