From 2636838a7ecb03e903f949cb9de89f67917fc699 Mon Sep 17 00:00:00 2001 From: Thomas Munzer Date: Wed, 28 Aug 2024 19:16:00 +0200 Subject: [PATCH] fix inventory validation --- .../resource_org_inventory/org_inventory_resource_gen.go | 8 +++----- internal/resource_org_inventory/sdk_to_terraform.go | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/resource_org_inventory/org_inventory_resource_gen.go b/internal/resource_org_inventory/org_inventory_resource_gen.go index 4578c7f7..29cd14fc 100644 --- a/internal/resource_org_inventory/org_inventory_resource_gen.go +++ b/internal/resource_org_inventory/org_inventory_resource_gen.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" @@ -35,9 +34,8 @@ func OrgInventoryResourceSchema(ctx context.Context) schema.Schema { Description: "Device MAC address. Required to assign adopted devices to site. Removing an adopted device from the list will not release it, but will unassign it from the site. Cannot be specified when `claim_code` is used", MarkdownDescription: "Device MAC address. Required to assign adopted devices to site. Removing an adopted device from the list will not release it, but will unassign it from the site. Cannot be specified when `claim_code` is used", Validators: []validator.String{ - stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("claim_code")), mistvalidator.ParseMac(), - mistvalidator.RequiredWhenValueIs(path.MatchRelative().AtParent().AtName("claim_code"), types.StringNull()), + // mistvalidator.RequiredWhenValueIs(path.MatchRelative().AtParent().AtName("claim_code"), types.StringValue("")), }, }, "model": schema.StringAttribute{ @@ -54,8 +52,8 @@ func OrgInventoryResourceSchema(ctx context.Context) schema.Schema { Description: "Device Claim Code. Required for claimed devices. Removing an adopted device from the list will release it", MarkdownDescription: "Device Claim Code. Required for claimed devices. Removing an adopted device from the list will release it", Validators: []validator.String{ - stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("claim_code")), - mistvalidator.RequiredWhenValueIs(path.MatchRelative().AtParent().AtName("mac"), types.StringNull()), + stringvalidator.LengthAtLeast(15), + // mistvalidator.RequiredWhenValueIs(path.MatchRelative().AtParent().AtName("mac"), types.StringNull()), }, }, "serial": schema.StringAttribute{ diff --git a/internal/resource_org_inventory/sdk_to_terraform.go b/internal/resource_org_inventory/sdk_to_terraform.go index f5dcde4d..f28a48ed 100644 --- a/internal/resource_org_inventory/sdk_to_terraform.go +++ b/internal/resource_org_inventory/sdk_to_terraform.go @@ -129,12 +129,12 @@ func SdkToTerraform(ctx context.Context, orgId string, data []models.Inventory, checkVcSiteId(&dev_from_mist, vcmac_to_site) devices_out = append(devices_out, dev_from_mist) } else if magic != "" { - diags.AddError( + diags.AddWarning( "Device not in the Org Inventory", fmt.Sprintf("Device with Claim Code %s is not in the Org Inventory", magic), ) } else { - diags.AddError( + diags.AddWarning( "Device not in the Org Inventory", fmt.Sprintf("Device with MAC Address %s is not in the Org Inventory", mac), )