gitlab_repository_file (Resource)

The gitlab_repository_file resource allows to manage the lifecycle of a file within a repository.

Upstream API: GitLab REST API docs

Example Usage

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
}

Schema

Required

Optional

Read-Only

Nested Schema for timeouts

Optional:

Import

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