terraform-provider-gitlab icon indicating copy to clipboard operation
terraform-provider-gitlab copied to clipboard

Error creating Project from custom project templates

Open adriano-fonseca opened this issue 3 years ago • 5 comments

GitLab Provider version

3.16.1

GitLab version

GitLab Enterprise Edition 15.3.0-pre

Terraform version

3.16.1

Relevant Terraform Configuration

resource "gitlab_project" "aviator_proj" {
  name         = var.aviator_full_name
  namespace_id = var.root_group
  group_with_project_templates_id = redacted
  template_project_id = redacted
}


### Relevant log output

```shell
│ Error: POST https://gitlab.com/api/v4/projects: 400 {message: {template_name: ['' is unknown or invalid]}}
│ 
│   with gitlab_project.aviator_proj,
│   on aviator_llc.tf line 35, in resource "gitlab_project" "aviator_proj":
│   35: resource "gitlab_project" "aviator_proj" {
│ 
╵

Description

As per documentation template_name and template_project_id should be mutually exclusive. However, using template_id, I am getting a terraform error related to template_name.

adriano-fonseca avatar Aug 04 '22 15:08 adriano-fonseca

resource "gitlab_project" "aviator_proj" {
  name         = var.aviator_full_name
  namespace_id = var.root_group
  group_with_project_templates_id = 1234
  template_project_id = 12345
  use_custom_template = true
}

After double checking group_id where the template lives and the project_template_id. I am still getting the following:

Error: POST https://gitlab.com/api/v4/projects: 400 {message: {template_project_id: [4187442 is unknown or invalid]}}

Tricky to create projects from project templates. Do we have test for this feature?

adriano-fonseca avatar Aug 04 '22 15:08 adriano-fonseca

@adriano-fonseca Unfortunately, I didn't have the time yet to look closely at the problem here - However, it triggered some deja-vu ... for which the gitlab_group_project_file_template resource exists. Maybe you can already either make it work using this or correct me that this isn't what you are looking for 😇

Either way, I hope I can get back to this during the weekend. Maybe you know something, too @PatrickRice-KSC ?

timofurrer avatar Aug 04 '22 20:08 timofurrer

Yeah, there's a bit of an involved process in order to allow you to use a project as a template - you need to do the following steps:

  1. Create a Group, and a project within that group <which you've done>
  2. mark the group or project as being available for use as a template, that's the resource that timo is referencing above.
  3. Finally, reference the template project to create using the template like you're doing.

The error you're getting seems like step 2 is missing above, could you check out your GitLab group setup and see? To check that, you can navigate to the group that you are creating the new project with, go to "Settings > General" and check if the project is identified as a template correctly?

RicePatrick avatar Aug 04 '22 22:08 RicePatrick

@PatrickRice-KSC thanks for information!

I think it makes sense to improve our documentation for the gitlab_group_project_file_template resource and the corresponding affected attributes in the gitlab_project resource. I imagine some note in the latter for the attributes and a good example in the former. @PatrickRice-KSC would you mind taking this up?

timofurrer avatar Aug 05 '22 10:08 timofurrer

would you mind taking this up?

Yeah, no problem :)

RicePatrick avatar Aug 05 '22 12:08 RicePatrick

This functionality has been released in v3.17.0 of the Terraform GitLab Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue. Thank you!

github-actions[bot] avatar Aug 24 '22 18:08 github-actions[bot]

Does anyone maybe have a running example with this templates? I think I'm running in a quite similar issue but even with the example from new documentation I'm getting an error.

77│ Error: error while waiting for project "values" import to finish: unexpected state 'failed', wanted target 'finished'. last error: %!s(<nil>)

I describe it here: https://stackoverflow.com/questions/73582900/crate-gitlab-project-from-template-via-terraform

pderckx avatar Sep 02 '22 20:09 pderckx