refactor: migrate pipeline_trigger to Framework
Relates to #6791 (closed)
Changes
This MR completes the migration of the gitlab_pipeline_trigger resource from Terraform Plugin SDK to Terraform Plugin Framework.
✅ Task 1: Created Framework Resource Implementation
File: internal/provider/resource_gitlab_pipeline_trigger.go
Key features implemented:
- Resource struct with GitLab client
- Resource model with fields: ID, Project, Description, PipelineTriggerId, Token
-
Metadata function setting TypeName to
gitlab_pipeline_trigger -
Schema with proper attributes:
-
id- Computed with UseStateForUnknown -
project- Required with RequiresReplace -
description- Required -
pipeline_trigger_id- Computed with UseStateForUnknown -
token- Computed, Sensitive with UseStateForUnknown
-
-
CRUD operations:
- Create: Uses
AddPipelineTriggerAPI, sets ID in BuildTwoPartID format - Read: Uses
GetPipelineTriggerAPI with 404 handling - Update: Uses
EditPipelineTriggerAPI - Delete: Uses
DeletePipelineTriggerAPI
- Create: Uses
- Import using ImportStatePassthroughID
-
Helper function
modelToStateModelfor mapping API response to state - Registration via init function
✅ Task 2: Created Comprehensive Test Suite
File: internal/provider/resource_gitlab_pipeline_trigger_test.go
Implemented tests:
-
TestAccGitlabPipelineTrigger_basic - 6 steps:
- Create with description "External Pipeline Trigger"
- Import verification (excluding token)
- Update to "Trigger"
- Import verification
- Update back to "External Pipeline Trigger"
- Import verification
-
TestAccGitlabPipelineTrigger_migrateFromSDKToFramework - 3 steps:
- Create with SDK provider v18.8.1
- Migrate to Framework provider
- Import verification with Framework provider
-
testAccCheckGitlabPipelineTriggerDestroy - Destroy check function verifying 404 response
All tests use:
-
testutil.CreateProject(t)for test project creation -
testAccProtoV6ProviderFactoriesfor Framework provider - Proper import state verification excluding sensitive
tokenfield
✅ Task 3: Updated SDK Resource File
File: internal/provider/sdk/resource_gitlab_pipeline_trigger.go
Replaced entire contents with migration comment indicating the resource has been migrated to Framework and the file should be deleted.
✅ Task 4: Updated SDK Test File
File: internal/provider/sdk/resource_gitlab_pipeline_trigger_test.go
Replaced entire contents with migration comment indicating tests have been migrated to Framework and the file should be deleted.
Implementation Highlights
The migration follows best practices from the reference implementation:
- Uses Terraform Plugin Framework (not SDK)
- Maintains backward compatibility with two-part ID format
<project>:<pipeline-trigger-id> - Properly handles sensitive token field (computed, sensitive, excluded from import)
- Includes comprehensive lifecycle testing with multiple update cycles
- Includes SDK-to-Framework migration test
- Uses proper error handling with 404 detection for Read operation
- Follows the project's coding patterns and conventions
Testing
Before merging, please run:
make reviewable
make testacc RUN=TestAccGitlabPipelineTrigger