diff --git a/Readme.md b/Readme.md index a4fa9bd..12de65e 100644 --- a/Readme.md +++ b/Readme.md @@ -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/`. 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 diff --git a/main.tf b/main.tf index e514d69..154fc1f 100644 --- a/main.tf +++ b/main.tf @@ -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") diff --git a/tests/pipeline_schedules.tftest.hcl b/tests/pipeline_schedules.tftest.hcl new file mode 100644 index 0000000..f9fc5b9 --- /dev/null +++ b/tests/pipeline_schedules.tftest.hcl @@ -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/, 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." + } +} diff --git a/versions.tf b/versions.tf index 2a73634..081726b 100644 --- a/versions.tf +++ b/versions.tf @@ -2,7 +2,7 @@ terraform { required_providers { gitlab = { source = "gitlabhq/gitlab" - version = "= 19.1.0" + version = "= 19.5.0" } } required_version = ">= 1.8.0"