fix: inconsistent result on token rotation
Relates to issue #6689 (closed)
Changes
This MR fixes the "inconsistent result after apply" error for the gitlab_group_service_account_access_token resource by implementing proper default value handling for the validate_past_expiration_date field.
Root Cause
The issue occurred because the validate_past_expiration_date field was being set to false during Create/Update operations, but the plan expected it to be null when not explicitly configured. This created a mismatch between the planned value (null) and the actual value set into state (false), causing Terraform to report an inconsistency error.
Implementation Details
File: internal/provider/resource_gitlab_group_service_account_access_token.go
-
Added schema-level default (line 151):
- Added
Default: booldefault.StaticBool(false)to thevalidate_past_expiration_dateattribute - Ensures Terraform's plan correctly reflects the default value as
falseinstead ofnull
- Added
-
Added ModifyPlan default handling (lines 305-311):
- Implemented logic to set
validate_past_expiration_datetofalsewhen it'snullin the plan - Ensures the default is applied during the plan phase, preventing plan/apply mismatches
- Implemented logic to set
-
Removed manual defaults:
- Removed manual default setting from Create function (previously line 656)
- Removed manual default setting from Update function (previously line 754)
- The schema default now handles this automatically
-
Added required import:
- Added
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"to support schema-level defaults
- Added
Expected Outcome
-
✅ The plan will correctly showvalidate_past_expiration_date = falseinstead ofnull -
✅ The apply operation will not produce an "inconsistent result" error -
✅ Token rotation will work correctly without plan/apply mismatches -
✅ Existing tests should continue to pass, as they already expect the default behavior offalse
The implementation follows the same pattern used in other resources like gitlab_group_deploy_token and gitlab_project_deploy_token, ensuring consistency across the codebase.