I want to implement deploying repositories and groups on my self-managed Gitlab by a Terraform provider gitlabhq/gitlab. But I have this error:

╷
│ Error: error while waiting for branch  to reach 'protected' status, json: cannot unmarshal array into Go value of type gitlab.Branch
│ 
│   with gitlab_project.peters_repo,
│   on main.tf line 11, in resource "gitlab_project" "peters_repo":
│   11: resource "gitlab_project" "peters_repo" {
│ 
╵

My variables.tf:

variable "gitlab_token" {
  default = "*my token*"
}
variable "gitlab_url" {
  default = "*my gitlab url*"
}

variable "default_branch" {
  default = "master"
}

main.tf:

resource "gitlab_group" "example" {
  name        = "Example Group"
  path        = "example_group"
  description = "An example group"
}

resource "gitlab_project" "peters_repo" {
  name         = "test-repo"
  description  = "This is a description"
  namespace_id = gitlab_group.example.id

  default_branch = var.default_branch

  provisioner "local-exec" {
    command = "curl --request DELETE '${var.gitlab_url}/api/v4/projects/${gitlab_project.peters_repo.id}/protected_branches/${var.default_branch}' --header 'PRIVATE-TOKEN: ${var.gitlab_token}'"
  }
}

resource "gitlab_branch_protection" "example_protection" {
  project = gitlab_project.peters_repo.id
  branch  = var.default_branch

  push_access_level  = "maintainer"
  merge_access_level = "maintainer"
}

providers.tf:

terraform {
  required_version = "~> 1.4"

  required_providers {
    gitlab = {
      source  = "gitlabhq/gitlab"
      version = "15.10.0"
    }
  }
}

provider "gitlab" {
  token = var.gitlab_token
  base_url = "var.gitlab_url"
}

I made a local provisioner as mentioned in the official documentation, but it still doesn't work.

0

There are 0 best solutions below