refactor: migrate gitlab_group_ldap_link from SDK to Framework

Fixes #6796 (closed)

Changes

This MR completes the migration of the gitlab_group_ldap_link resource from Terraform Plugin SDK to Terraform Plugin Framework.

Task 1: Created Framework Resource Implementation

File: internal/provider/resource_gitlab_group_ldap_link.go

Key features implemented:

  • Resource struct with GitLab client
  • Resource model with fields: ID, Group, CN, Filter, GroupAccess, MemberRoleID, LdapProvider, Force
  • Metadata function setting TypeName to gitlab_group_ldap_link
  • Schema with proper attributes:
    • id - Computed with UseStateForUnknown, format <group>:<ldap_provider>:<cn>:<filter>
    • group - Required with RequiresReplace
    • cn - Optional, Computed with RequiresReplace and ConflictsWith filter
    • filter - Optional, Computed with RequiresReplace and ConflictsWith cn
    • group_access - Required with RequiresReplace and OneOf validator
    • member_role_id - Optional, Computed with RequiresReplace
    • ldap_provider - Required with RequiresReplace
    • force - Optional, Computed with default false and RequiresReplace
  • CRUD operations:
    • Create: Uses AddGroupLDAPLink API, handles force flag to delete existing links first
    • Read: Uses ListGroupLDAPLinks API with 403/404 handling
    • Update: No-op (all attributes require replacement)
    • Delete: Uses DeleteGroupLDAPLinkWithCNOrFilter API
  • Import using ImportStatePassthroughID
  • Registration via init function

The ID format is preserved from the SDK version: <group>:<ldap_provider>:<cn>:<filter>

Task 2: Created Comprehensive Test Suite

File: internal/provider/resource_gitlab_group_ldap_link_test.go

Implemented tests:

  1. TestAccGitlabGroupLdapLink_basicCN - Create/import/update cycle using CN
  2. TestAccGitlabGroupLdapLink_basicFilter - Create/import using filter
  3. TestAccGitlabGroupLdapLink_removeOutsideTf - Tests behavior when group is deleted outside TF
  4. TestAccGitlabGroupLdapLink_recreatedWhenRemoved - Tests re-creation when LDAP link is deleted outside TF
  5. TestAccGitlabGroupLdapLink_forceDeletesWhenExists - Tests force flag behavior
  6. TestAccGitlabGroupLdapLink_migrateFromSDKToFramework - Tests migration from SDK provider v18.10.0 to Framework

Task 3: Updated SDK Resource File

File: internal/provider/sdk/resource_gitlab_group_ldap_link.go

Replaced entire contents with migration comment indicating the resource has been migrated to Framework.

Task 4: Updated SDK Test File

File: internal/provider/sdk/resource_gitlab_group_ldap_link_test.go

Replaced entire contents with migration comment indicating tests have been migrated to Framework.

Implementation Highlights

  • Maintains backward compatibility with the existing 4-part ID format <group>:<ldap_provider>:<cn>:<filter>
  • Properly handles the force attribute for deleting and replacing existing LDAP links
  • Handles 403 errors when the parent group is removed (with force=true)
  • Handles 404 errors when no LDAP links exist (API returns 404 for empty list)
  • Supports member_role_id for custom roles (Ultimate instances)
  • Includes SDK-to-Framework migration test

Testing

Before merging, please run:

make reviewable
make testacc RUN=TestAccGitlabGroupLdapLink
Edited by Heidi Berry

Merge request reports

Loading
Loading