Skip to content

Commit

Permalink
Update SAML link read to use new Get endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mhodgson committed Aug 17, 2022
1 parent b82c246 commit e7a2020
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions internal/provider/resource_gitlab_group_saml_link.go
Expand Up @@ -88,31 +88,20 @@ func resourceGitlabGroupSamlLinkRead(ctx context.Context, d *schema.ResourceData

// Try to fetch all group links from GitLab
log.Printf("[DEBUG] Read GitLab group SamlLinks %s", group)
samlLinks, _, err := client.Groups.ListGroupSAMLLinks(group, nil, gitlab.WithContext(ctx))
samlLink, _, err := client.Groups.GetGroupSAMLLink(group, samlGroupName, nil, gitlab.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
}

if samlLinks != nil {
// Check if the SAML link exists in the returned list of links
found := false
for _, samlLink := range samlLinks {
if samlLink.Name == samlGroupName {
d.Set("group", group)
d.Set("access_level", samlLink.AccessLevel)
d.Set("saml_group_name", samlLink.Name)
found = true
break
}
}

if !found {
if is404(err) {
log.Printf("[DEBUG] GitLab SAML Group Link %d, group ID %s not found, removing from state", samlGroupName, group)
d.SetId("")
return nil
}
return diag.FromErr(err)
}

d.Set("group", group)
d.Set("access_level", samlLink.AccessLevel)
d.Set("saml_group_name", samlLink.Name)

return nil
}

Expand Down

0 comments on commit e7a2020

Please sign in to comment.