Skip to content

Manually deleted pipeline schedule causes a 404 error on plan

Bug Report

I took ownership of a pipeline schedule to see if there was a variable set, and then deleted it, expecting to recreate it in terraform

My plan produced this error:

Terraform planned the following actions, but then encountered a problem:
  # gitlab_pipeline_schedule.repo_approvals_project will be created
  + resource "gitlab_pipeline_schedule" "repo_approvals_project" {
      + active               = true
      + cron                 = "0 7 * * *"
      + cron_timezone        = "America/Chicago"
      + description          = "Enforce SH Gitlab approval settings"
      + id                   = (known after apply)
      + owner                = (known after apply)
      + pipeline_schedule_id = (known after apply)
      + project              = "5289XXXX"
      + ref                  = "master"
    }
Plan: 1 to add, 0 to change, 0 to destroy.

│ Error: GET https://gitlab.com/api/v4/projects/5289XXXX/pipeline_schedules/1489752: 404 {message: 404 Pipeline Schedule Not Found}

│   with gitlab_pipeline_schedule_variable.repo_approvals_project_variable,
│   on repo_approvals_project.tf line 33, in resource "gitlab_pipeline_schedule_variable" "repo_approvals_project_variable":
│   33: resource "gitlab_pipeline_schedule_variable" "repo_approvals_project_variable" {

It appears there was a similar issue: #699 (closed) that had a PR merged: !318 (merged)

I would have expected the provider to realize that the pipeline schedule had been deleted and to recreate the resource. I worked around this by removing the orphaned schedule and variable from the state:

terraform state rm gitlab_pipeline_schedule.repo_approvals_project (still got the error after deleting this from the state)
terraform state rm gitlab_pipeline_schedule_variable.repo_approvals_project_variable (error no longer there)

Relevant Terraform Configuration

resource "gitlab_pipeline_schedule" "repo_approvals_project" {
  project       = data.gitlab_project.repo_approvals_project.id
  description   = "Enforce Gitlab approval settings"
  ref           = "master"
  cron          = "0 7 * * *"
  active        = true
  cron_timezone = "America/Chicago"
}

resource "gitlab_pipeline_schedule_variable" "repo_approvals_project_variable" {
  project              = gitlab_pipeline_schedule.repo_approvals_project.project
  pipeline_schedule_id = gitlab_pipeline_schedule.repo_approvals_project.pipeline_schedule_id
  key                  = "SCHEDULED"
  value                = "true"
}


.gitlabci.yaml (partial)

apply:
  <<: *tags
  extends: .apply
  rules:
    - if: $SCHEDULED
      when: always
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual

Relevant Terraform Command

terraform plan -out=plan.tfplan

Relevant Log Output

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

Additional Details

  • GitLab Terraform Provider Version: v16.6.0
  • GitLab Version: GitLab Enterprise Edition 16.8.0-pre 7ff087dae84
  • Terraform Version: 1.6.2