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 RequiresReplacecn- Optional, Computed with RequiresReplace and ConflictsWith filterfilter- Optional, Computed with RequiresReplace and ConflictsWith cngroup_access- Required with RequiresReplace and OneOf validatormember_role_id- Optional, Computed with RequiresReplaceldap_provider- Required with RequiresReplaceforce- Optional, Computed with default false and RequiresReplace
- CRUD operations:
- Create: Uses
AddGroupLDAPLinkAPI, handlesforceflag to delete existing links first - Read: Uses
ListGroupLDAPLinksAPI with 403/404 handling - Update: No-op (all attributes require replacement)
- Delete: Uses
DeleteGroupLDAPLinkWithCNOrFilterAPI
- Create: Uses
- 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:
- TestAccGitlabGroupLdapLink_basicCN - Create/import/update cycle using CN
- TestAccGitlabGroupLdapLink_basicFilter - Create/import using filter
- TestAccGitlabGroupLdapLink_removeOutsideTf - Tests behavior when group is deleted outside TF
- TestAccGitlabGroupLdapLink_recreatedWhenRemoved - Tests re-creation when LDAP link is deleted outside TF
- TestAccGitlabGroupLdapLink_forceDeletesWhenExists - Tests force flag behavior
- 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
forceattribute 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_idfor custom roles (Ultimate instances) - Includes SDK-to-Framework migration test
Testing
Before merging, please run:
make reviewable
make testacc RUN=TestAccGitlabGroupLdapLink