gitlab_repository_file resource cant update/overwrite existing files

Created by: switchboardOp

Feature Description

When trying to update a file which isn't already in TF state using the gitlab_repository_file resource the provider produces the below error:

gitlab_repository_file.foo: Creating...

Error: POST https://gitlab.com/api/v4/projects/[REDACTED]/repository/files/foo: 400 {message: A file with this name already exists}

  on main.tf line 7, in resource "gitlab_repository_file" "foo":
   7: resource gitlab_repository_file foo {

It may go against conventional Terraform wisdom to modify existing resources without first importing them to state, but this could be very handy for bringing a large number of files under management by Terraform. My use case is programmatically managing existing CODEOWNERS files for all repos under a group.

Looking at the API docs it looks like this would mean performing a PUT rather than a POST request. I propose adding an argument to the resource to allow overwriting files.

A similar issue was reported and implemented for the GitHub provider.

Do you want to implement this?

  • I would like to implement this myself 👷
Edited by Timo Furrer