Allow setting CI/CD Catalog project boolean in gitlab_project resource
New Data Source / Resource
Add a boolean to the project resource that allows the project to be set as a CI/CD Component Catalog. This is currently only possible via the UI: https://docs.gitlab.com/ee/ci/components/#set-a-component-project-as-a-catalog-project.
This would allow up to setup CI/CD Catalog projects completely through TF without needing to go to the UI to configure them.
Related GitLab APIs
API documentation (This requires GraphQL):
- Create: https://docs.gitlab.com/ee/api/graphql/reference/#mutationcatalogresourcescreate
- Destroy: https://docs.gitlab.com/ee/api/graphql/reference/#mutationcatalogresourcescreate
- Query: https://docs.gitlab.com/ee/api/graphql/reference/#querycicatalogresource
Implementation Details
Since this API is different from the Create Project API, we will create a new resource for this call: gitlab_project_cicd_catalog
. This follows the TF convention of one-resource-per-api, and makes it cleaner for end users in the event of a failure.
To implement this, we will do the following:
- Create a new
resource_gitlab_project_cicd_catalog
under https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/tree/main/internal/provider?ref_type=heads- This will be implemented based on the Plugin Framework method of development, which has a walkthrough here: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/development/CreatingANewResource.md?ref_type=heads
- Since GraphQL calls usually use the GraphQL "global ID" instead of our standard projectID/projectPath, we may need to make an additional
query.Project
call to get the global Id from the project using the ID or Path to stay consistent. Alternatively, we could add a call in thegitlab_project
resource and add a newproject_guid
attribute that returns the GraphQL ID, so that users could input that ID to this resource.
- New GraphQL structs will be added to that resource that match the response structure of the GraphQL calls made to the API. See example of that here: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/internal/provider/resource_gitlab_compliance_framework.go?ref_type=heads#L462
- Using those new GraphQL structs, the
SendGraphQLRequest
function in theapi
package can be used to send the proper request.- See example of parsing the response to struct here: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/internal/provider/resource_gitlab_compliance_framework.go?ref_type=heads#L425
- See example of creating the query and sending it here: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/internal/provider/resource_gitlab_compliance_framework.go?ref_type=heads#L233
- Finally, new tests should be added for the Catalog setting. The tests should use
testutils
to create a Project, then use the newgitlab_project_cicd_catalog
resource to toggle the value. Since this resource only accepts the project guid, and that attribute should beForceNew: True
, the tests really only need to test create, destroy, and import; since any change to the resource will result in a Destroy -> Create operation.
Additional Details
-
GitLab REST API resources available (read for data sources, crud for resources) - N/A, uses GraphQL -
go-gitlab
does support the related GitLab API already - N/A, users GraphQL -
I'd like to contribute it myself
Edited by Zachary Yates