Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ This Terraform module provides resources to manage GitLab groups, projects, inte
## Requirements

- Terraform 1.8.0 or higher.
- GitLab Provider for Terraform 19.0.0 or higher. See [docs/UPGRADE-2.0.md](docs/UPGRADE-2.0.md) if upgrading from a 18.x-based release of this module.
- GitLab Provider for Terraform 19.5.0. The module pins this exact version. After you change the module version, run `terraform init -upgrade`. See [docs/UPGRADE-2.0.md](docs/UPGRADE-2.0.md) if upgrading from a 18.x-based release of this module.

## Notes

- `pipeline_schedules[*].ref` accepts a short branch name (`main`) or a full ref (`refs/heads/main`, `refs/tags/v1.0.0`). The module changes a short name to `refs/heads/<name>`. For a tag, use the full ref.
- The provider deprecated the `push_rules` block of `gitlab_project` in 19.4.1 and removes it in 20.0. The module uses this block for project `push_rules`, and the plan shows a deprecation warning.

## Usage

Expand Down
5 changes: 4 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1284,13 +1284,16 @@ resource "gitlab_pipeline_schedule" "this" {
project_name = project.name
project_namespace = project.namespace
pipeline_schedule = pipeline
# Provider >= 19.4.1 accepts only a full ref. A short ref is a branch name.
# The for_each key keeps the ref as written, so the addresses do not change.
full_ref = startswith(pipeline.ref, "refs/") ? pipeline.ref : "refs/heads/${pipeline.ref}"
}
}
]...)

project = gitlab_project.this["${each.value.project_namespace}/${each.value.project_name}"].id
description = each.value.pipeline_schedule.description
ref = each.value.pipeline_schedule.ref
ref = each.value.full_ref
cron = each.value.pipeline_schedule.cron
active = lookup(each.value.pipeline_schedule, "active", false)
cron_timezone = lookup(each.value.pipeline_schedule, "cron_timezone", "UTC")
Expand Down
38 changes: 38 additions & 0 deletions tests/pipeline_schedules.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Unit tests for the ref of pipeline schedules. They use a mock provider and do not call GitLab.

mock_provider "gitlab" {}

variables {
gitlab_groups = []
gitlab_projects = [
{
name = "api"
namespace = "alpha"
create = true
settings = {
pipeline_schedules = [
{ description = "nightly", ref = "main", cron = "0 1 * * *" },
{ description = "release", ref = "refs/tags/v1.0.0", cron = "0 2 * * *" },
]
}
},
]
}

run "short_ref_becomes_a_full_branch_ref" {
command = plan

assert {
condition = gitlab_pipeline_schedule.this["alpha-api-main-nightly"].ref == "refs/heads/main"
error_message = "A short ref must become refs/heads/<ref>, and the key must keep the ref as written."
}
}

run "full_ref_does_not_change" {
command = plan

assert {
condition = gitlab_pipeline_schedule.this["alpha-api-refs/tags/v1.0.0-release"].ref == "refs/tags/v1.0.0"
error_message = "A full ref must not change."
}
}
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
gitlab = {
source = "gitlabhq/gitlab"
version = "= 19.1.0"
version = "= 19.5.0"
}
}
required_version = ">= 1.8.0"
Expand Down
Loading