Add existing API field empty_repo to data source gitlab_project
empty_repo
to Data Source gitlab_project
Add missing API field I'm reading the repository trees dynamically with the data resource gitlab_repository_tree
, and from time to time there could be a repository which has not yet been initialised. API tree
fails with 404 for non-initialised repositories. To safeguard against this, I would like to put a condition on the empty_repo
flag. However, this is not included in terraform provider.
Adding the empty_repo
I can secure my code something in the following way:
data "gitlab_project" "self" {
path_with_namespace = var.project_path
}
data "gitlab_repository_tree" "self" {
count = data.gitlab_project.self.empty_repo ? 0 : 1
project = data.gitlab_project.self.path_with_namespace
ref = data.gitlab_project.self.default_branch
}
locals {
gitlab_repo_tree = one(data.gitlab_repository_tree.self[*])
has_file = try(contains(local.gitlab_repo_tree.tree[*].name, "file_name"), false)
}
Related GitLab APIs
Field is poorly documented in API documentation but can be seen in example responses.
Field is already available in go client.
Additional Details
-
GitLab REST API resources available (read for data sources, crud for resources) -
go-gitlab
does support the related GitLab API already -
I'd like to contribute it myself
Edited by Henrik Sandberg