From f7fd54d139a4a3baa28a65291ae3e066365cab46 Mon Sep 17 00:00:00 2001 From: Nathan Bartlett Date: Thu, 16 Jul 2020 14:55:20 +1000 Subject: [PATCH 1/2] Added check for exact group name match on group data source. --- okta/data_source_okta_group.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/okta/data_source_okta_group.go b/okta/data_source_okta_group.go index 5b870de2a..00aa62bff 100644 --- a/okta/data_source_okta_group.go +++ b/okta/data_source_okta_group.go @@ -49,6 +49,10 @@ func findGroup(name string, d *schema.ResourceData, m interface{}) error { return fmt.Errorf("failed to query for groups: %v", err) } else if len(groups) < 1 { return errors.New("Group not found") + } else if len(groups) > 1 { + fmt.Println("Found multiple groups with the supplied parameters. Using the first one which may only be a partial match.") + } else if len(groups[0].Profile.Name) != len(name) { + fmt.Println("Group with exact match to the supplied name not found. Using partial match which contains name as a substring.") } d.SetId(groups[0].Id) From 2f79b47abbb2e691998f3628a075c2a040fa0125 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Wed, 16 Dec 2020 22:52:19 +0200 Subject: [PATCH 2/2] Merged with master --- okta/data_source_okta_group.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/okta/data_source_okta_group.go b/okta/data_source_okta_group.go index 92d43b0aa..1be17c4e3 100644 --- a/okta/data_source_okta_group.go +++ b/okta/data_source_okta_group.go @@ -64,9 +64,9 @@ func findGroup(ctx context.Context, name string, d *schema.ResourceData, m inter } return diag.Errorf("group with name '%s' does not exist", name) } else if len(groups) > 1 { - fmt.Println("Found multiple groups with the supplied parameters. Using the first one which may only be a partial match.") + logger(m).Warn("Found multiple groups with the supplied parameters: using the first one which may only be a partial match", "name", groups[0].Profile.Name) } else if len(groups[0].Profile.Name) != len(name) { - fmt.Println("Group with exact match to the supplied name not found. Using partial match which contains name as a substring.") + logger(m).Warn("The group with an exact match to the supplied name was not found: using partial match which contains name as a substring", "name", groups[0].Profile.Name) } d.SetId(groups[0].Id) _ = d.Set("description", groups[0].Profile.Description)