terraform-provider-gitlab
terraform-provider-gitlab copied to clipboard
Error creating Project from custom project templates
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.
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 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 ?
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:
- Create a Group, and a project within that group <which you've done>
- mark the group or project as being available for use as a template, that's the resource that timo is referencing above.
- 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?
@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?
would you mind taking this up?
Yeah, no problem :)
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!
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