Skip to content

Import of integration/hook requires project id, but converts to project name on subsequent plan

Created by: olhado

GitLab Provider version

3.16.0

GitLab version

Gitlab 14.5.2 EE

Terraform version

1.3.2

Relevant Terraform Configuration

No response

Relevant log output

########## Planning after importing a hook
# module.groups["foo"].gitlab_project_hook.integration["bar"] will be updated in-place
  ~ resource "gitlab_project_hook" "integration" {
        id                         = "111"
      ~ project                    = "1234" -> "bar"
        # (14 unchanged attributes hidden)
    }
####################
########## Planning after importing the jira service of a project
  # module.groups["foo"].gitlab_service_jira.integration["bar"] must be replaced
-/+ resource "gitlab_service_jira" "integration" {
      ~ active                   = true -> (known after apply)
      + api_url                  = (known after apply)
      ~ created_at               = "2022-01-01 00:00:00.001 +0000 UTC" -> (known after apply)
      ~ id                       = "111" -> (known after apply)
      ~ issues_events            = true -> (known after apply)
      ~ job_events               = true -> (known after apply)
      ~ note_events              = true -> (known after apply)
      + password                 = (sensitive value)
      ~ pipeline_events          = true -> (known after apply)
      ~ project                  = "1234" -> "bar" # forces replacement
      ~ push_events              = true -> (known after apply)
      ~ tag_push_events          = true -> (known after apply)
      ~ title                    = "Jira" -> (known after apply)
      ~ updated_at               = "2022-01-07 00:00:00.001 +0000 UTC" -> (known after apply)
        # (4 unchanged attributes hidden)
    }

Description

Using terraform import requires a project id, and will throw an error if a project name is used. However, if you then run a terraform plan, it says the resource is going to change because the project ID is being converted to the project name. For the jira service/integration, this is even worse as it does a destroy/create replace cycle precisely because the project id is being converted to the project name.

It seems like the easiest ways to fix would be to:

  • Allow import by project name if possible, though you'd need to validate that the name is unique/handle full-path of project.
  • During the import save the project name as the id in the state file. This seems the most straightforward.
Edited by Timo Furrer