Fix the schema version 0 state upgrade of gitlab_pipeline_trigger
What does this MR do and why?
A gitlab_pipeline_trigger whose state is still at schema version 0 can't be planned since 18.11.0: terraform plan stops with "Missing Upgraded Resource State" before it sends any request to GitLab. Schema version 0 is what provider 15.11.0 and earlier wrote; 16.0.0 changed the ID to <project>:<trigger_id> and added a state upgrader, and every release up to 18.10.0 upgrades such a state when it reads it, so the states left at version 0 are the ones none of those releases refreshed.
When !3011 (merged) moved the resource to the plugin framework, the new version 0 upgrader kept building the new ID but stopped writing the upgraded state into the response (resource_gitlab_pipeline_trigger.go#L291-312), so the framework has nothing to return and fails.
This MR writes it with resp.State.Set, as the other framework upgraders do (for example resource_gitlab_project_hook.go#L424). The schema doesn't change.
Two new acceptance tests create a pipeline trigger with provider 15.11.0, the last release that stores it at schema version 0, and then plan and apply the same configuration with this provider: TestAccGitlabPipelineTrigger_schemaMigrationV0toV1 gives the project by its ID and TestAccGitlabPipelineTrigger_schemaMigrationV0toV1WithProjectPath by its path, since the version 1 ID is built from the project as configured. In both, the plan has no changes, the ID becomes <project>:<trigger_id> with the trigger ID the version 0 state held, the token comes through the upgrade unchanged, and an import of the trigger matches the upgraded state. Like the SDK to Framework test next to them, they skip on CE. The destroy check now looks at every trigger in the state instead of returning after the first one it finds.
15.11.0 is added to .gitlab/ci/external-providers.txt, which TestExternalProvidersAreMirrored requires of every ExternalProviders entry. Because that file changes, the pipeline builds the CI image again, and the acceptance jobs pull it from this project's registry. The community fork has its container registry disabled, so in its pipelines acctest:image fails and go:test and the acceptance jobs are skipped; the acceptance run needs a pipeline in this project.
Closes #6908 (closed)
How to verify
make testacc-up SERVICE=gitlab-ee
make testacc RUN=TestAccGitlabPipelineTrigger_The new tests skip on CE, so they need the EE image; they don't need a license. With the upgrader as it is on main, both fail at their second step with "Missing Upgraded Resource State"; with this change the four pipeline trigger tests pass.
What I ran (Go 1.26.5, Terraform 1.4.0 for the tests and 1.13.4 for the CLI run, GitLab EE 19.5.0 without a license)
The new tests with the upgrader as it is on main:
=== NAME TestAccGitlabPipelineTrigger_schemaMigrationV0toV1
resource_gitlab_pipeline_trigger_test.go:106: Step 2/3 error: Error running pre-apply plan: exit status 1
Error: Missing Upgraded Resource State
with gitlab_pipeline_trigger.test,
on terraform_plugin_test.tf line 12, in resource "gitlab_pipeline_trigger" "test":
12: resource "gitlab_pipeline_trigger" "test" {
After attempting a resource state upgrade to version 0, the provider did not
return any state data. Preventing the unexpected loss of resource state data.
This is always an issue with the Terraform Provider and should be reported to
the provider developer.
panic.go:694: Error retrieving state, there may be dangling resources: exit status 1
Failed to marshal state to json: schema version 0 for gitlab_pipeline_trigger.test in state does not match version 1 from the provider
--- FAIL: TestAccGitlabPipelineTrigger_schemaMigrationV0toV1 (5.92s)
--- FAIL: TestAccGitlabPipelineTrigger_schemaMigrationV0toV1WithProjectPath (6.38s)TestAccGitlabPipelineTrigger_schemaMigrationV0toV1WithProjectPath fails the same way, at its second step too.
This branch:
--- PASS: TestAccGitlabPipelineTrigger_basic (6.67s)
--- PASS: TestAccGitlabPipelineTrigger_schemaMigrationV0toV1 (10.25s)
--- PASS: TestAccGitlabPipelineTrigger_schemaMigrationV0toV1WithProjectPath (10.33s)
--- PASS: TestAccGitlabPipelineTrigger_migrateFromSDKToFramework (11.03s)That was the first of three runs with -count=3; all twelve passed. The four tests pass as well on this branch merged with the current main, with Go 1.26.10. Moving resp.State.Set before the ID is rewritten, or dropping the rewrite, makes both new tests fail again, at their second step with "Invalid ID format". Without the new line in .gitlab/ci/external-providers.txt, TestExternalProvidersAreMirrored fails with no mirrored version of "gitlabhq/gitlab" matches "~> 15.11.0".
End to end with the Terraform CLI, against a stand-in server answering the pipeline trigger create and read requests: provider 15.11.0 applied the configuration below and stored the trigger at schema version 0, with "id": "42" and no pipeline_trigger_id. With that state, terraform plan failed with 19.4.1 and with a build of main, before sending any request:
Error: Missing Upgraded Resource State
with gitlab_pipeline_trigger.example,
on main.tf line 16, in resource "gitlab_pipeline_trigger" "example":
16: resource "gitlab_pipeline_trigger" "example" {
After attempting a resource state upgrade to version 0, the provider did not
return any state data. Preventing the unexpected loss of resource state data.
This is always an issue with the Terraform Provider and should be reported to
the provider developer.With a build of this branch the plan reported no changes, and after terraform apply -refresh-only the state was at schema version 1 with id = "foo/bar:42" and pipeline_trigger_id = 42.
resource "gitlab_pipeline_trigger" "example" {
project = "foo/bar"
description = "Trigger"
}make test, make lint-golangci (0 issues), lint-tfprovider, lint-custom, gofmt -s and go vet -tags acceptance pass, on this branch and merged with main, and terraform providers mirror with Terraform 1.4.0, the step the CI image runs for each line of the mirror list, fetches 15.11.0.