Add validation to ensure gitlab_project_membership.expires_at is in the future

Bug Report

Hey, we are working towards managing our gitlab resources via terraform. For that we have a own tf repo with a nightly pipeline that terraform applys the current configuration. One of the resources we have trouble with are `gitlab_project_memberships with an expiration date. Here's what I think is happening

31.08.

  • Expiration data is reached -> member is removed on gitlab side
  • terraform apply pipeline recreates member with same expiration date 01.09
  • Member is removed on gitlab side again
  • terraform apply pipeline recreates member with same expiration date -> this now fails with 400 {message: {expires_at: [cannot be a date in the past]}}
  • manual removal of gitlab_project_membership is needed

Relevant Terraform Configuration

resource "gitlab_project_membership" "membership" {
  project      = "123456"
  user_id      = 543210
  access_level = "maintainer"
  expires_at = "2025-08-31"
}

Relevant Terraform Command

terraform apply

Relevant Log Output

These are the debug logs of the `terraform` command output:

Terraform will perform the following actions:
  # gitlab_project_membership.membership will be created
  + resource "gitlab_project_membership" "membership" {
      + access_level = "maintainer"
      + expires_at   = "2025-08-31"
      + id           = (known after apply)
      + project      = "123456"
      + user_id      = 543210
    }
Plan: 1 to add, 0 to change, 0 to destroy.
gitlab_project_membership.membership: Creating...

│ Error: POST https://gitlab.com/api/v4/projects/123456/members: 400 {message: {expires_at: [cannot be a date in the past]}}

│   with gitlab_project_membership.membership,
│   on main.tf line 173, in resource "gitlab_project_membership" "membership":
│  173: resource "gitlab_project_membership" "membership" {

Additional Details

  • GitLab Terraform Provider Version: 17.11.0
  • GitLab Instance Version: cloud
  • Terraform Version: v1.13.1
  • License Tier: Premium
Edited by 🤖 GitLab Bot 🤖