From 4e1c0e056f84dcfc35f17ed7ef3ee8cb0934822b Mon Sep 17 00:00:00 2001 From: wgjak47 Date: Thu, 4 Apr 2024 21:49:12 +0800 Subject: [PATCH] fix: wrong result of data rancher2_principal --- rancher2/data_source_rancher2_principal.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rancher2/data_source_rancher2_principal.go b/rancher2/data_source_rancher2_principal.go index e7c80b2ed..9e087431c 100644 --- a/rancher2/data_source_rancher2_principal.go +++ b/rancher2/data_source_rancher2_principal.go @@ -58,12 +58,13 @@ func dataSourceRancher2PrincipalRead(d *schema.ResourceData, meta interface{}) e return err } - count := len(principals.Data) - if count <= 0 { - return fmt.Errorf("[ERROR] principal \"%s\" of type \"%s\" not found", name, principalType) + for _, principal := range principals.Data { + if principal.Name == name { + return flattenDataSourcePrincipal(d, &principal) + } } - return flattenDataSourcePrincipal(d, &principals.Data[0]) + return fmt.Errorf("[ERROR] principal \"%s\" of type \"%s\" not found", name, principalType) } func flattenDataSourcePrincipal(d *schema.ResourceData, in *managementClient.Principal) error {