From e0d47f149eadd83a22cdf7b7a89b979b14f9c4ca Mon Sep 17 00:00:00 2001 From: William Park Date: Tue, 17 Oct 2023 07:59:12 -0700 Subject: [PATCH] Improve item section and field ID generation --- onepassword/resource_onepassword_item.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/onepassword/resource_onepassword_item.go b/onepassword/resource_onepassword_item.go index 5bf94b9b..47ba2e69 100644 --- a/onepassword/resource_onepassword_item.go +++ b/onepassword/resource_onepassword_item.go @@ -546,19 +546,17 @@ func dataToItem(data *schema.ResourceData) (*onepassword.Item, error) { if !ok { return nil, fmt.Errorf("Unable to parse section: %v", sections[i]) } - sid, err := uuid.GenerateUUID() - if err != nil { - return nil, fmt.Errorf("Unable to generate a section id: %w", err) - } - if section["id"].(string) != "" { - sid = section["id"].(string) - } else { + if section["id"].(string) == "" { + sid, err := uuid.GenerateUUID() + if err != nil { + return nil, fmt.Errorf("Unable to generate a section id: %w", err) + } section["id"] = sid } s := &onepassword.ItemSection{ - ID: sid, + ID: section["id"].(string), Label: section["label"].(string), } item.Sections = append(item.Sections, s) @@ -570,6 +568,14 @@ func dataToItem(data *schema.ResourceData) (*onepassword.Item, error) { return nil, fmt.Errorf("Unable to parse section field: %v", sectionFields[j]) } + if field["id"].(string) == "" { + fid, err := uuid.GenerateUUID() + if err != nil { + return nil, fmt.Errorf("Unable to generate a field id: %w", err) + } + field["id"] = fid + } + f := &onepassword.ItemField{ Section: s, ID: field["id"].(string),