The gitlab_repository_file
resource allows to manage the lifecycle of a file within a repository.
Upstream API: GitLab REST API docs
resource "gitlab_group" "this" {
name = "example"
path = "example"
description = "An example group"
}
resource "gitlab_project" "this" {
name = "example"
namespace_id = gitlab_group.this.id
initialize_with_readme = true
}
resource "gitlab_repository_file" "this" {
project = gitlab_project.this.id
file_path = "meow.txt"
branch = "main"
content = base64encode("Meow goes the cat")
author_email = "terraform@example.com"
author_name = "Terraform"
commit_message = "feature: add meow file"
}
resource "gitlab_repository_file" "readme" {
project = gitlab_project.this.id
file_path = "readme.txt"
branch = "main"
// content will be auto base64 encoded
content = "Meow goes the cat"
author_email = "terraform@example.com"
author_name = "Terraform"
commit_message = "feature: add readme file"
}
resource "gitlab_repository_file" "readme_for_dogs" {
project = gitlab_project.this.id
file_path = "readme.txt"
branch = "main"
content = "Bark goes the dog"
author_email = "terraform@example.com"
author_name = "Terraform"
commit_message = "feature: update readme file"
// file will be overwritten if it already exists and added to state
overwrite_on_create = true
}
branch
(String) Name of the branch to which to commit to.content
(String) File content.file_path
(String) The full path of the file. It must be relative to the root of the project without a leading slash /
or ./
.project
(String) The name or ID of the project.author_email
(String) Email of the commit author.author_name
(String) Name of the commit author.commit_message
(String) Commit message.create_commit_message
(String) Create commit message.delete_commit_message
(String) Delete Commit message.encoding
(String) The file content encoding. Default value is base64
. Valid values are: base64
, text
.execute_filemode
(Boolean) Enables or disables the execute flag on the file. Note: requires GitLab 14.10 or newer.overwrite_on_create
(Boolean) Enable overwriting existing files, defaults to false
. This attribute is only used during create
and must be use carefully. We suggest to use imports
whenever possible and limit the use of this attribute for when the project was imported on the same apply
. This attribute is not supported during a resource import.start_branch
(String) Name of the branch to start the new commit from.timeouts
(Block, Optional) (see below for nested schema)update_commit_message
(String) Update commit message.blob_id
(String) The blob id.commit_id
(String) The commit id.content_sha256
(String) File content sha256 digest.file_name
(String) The filename.id
(String) The ID of this resource.last_commit_id
(String) The last known commit id.ref
(String) The name of branch, tag or commit.size
(Number) The file size.timeouts
Optional:
create
(String)delete
(String)update
(String)Import is supported using the following syntax:
# A Repository File can be imported using an id made up of `<project-id>:<branch-name>:<file-path>`, e.g.
terraform import gitlab_repository_file.this 1:main:foo/bar.txt