Report this

What is the reason for this report?

how to setup gitlab to create repositories

Posted on December 15, 2021

This does not work:

  • File: create.tf

terraform {
  required_providers {
    gitlab = {
      source = "gitlabhq/gitlab"
    }
  }
}
variable "gitlab_token" {
  type = string
  default = "SECRET"
}
variable "base_url" {
  type = string
  default = "https://gitlab.com/errooorr/api/v4/"
}
provider "gitlab" {
    token = var.gitlab_token
    base_url = var.base_url
  • and file: terraform.tfvars:
gitlab_token = blablabla


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

It looks like you haven’t closed your provider block. Your create.tf file should be like the following:

terraform {
  required_providers {
    gitlab = {
      source = "gitlabhq/gitlab"
    }
  }
}

variable "gitlab_token" {
  type = string
  default = "SECRET"
}

variable "base_url" {
  type = string
  default = "https://gitlab.com/errooorr/api/v4/"
}

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

Your terraform.tfvars file is correctly set up. The terraform variables file should be like this:

gitlab_token = "blablabla"

Ensure you replace "blablabla" with your actual GitLab token.

A couple of other points to consider:

  1. Check that your base_url is correct. The base url should be the GitLab API endpoint. The usual endpoint for GitLab’s API is https://gitlab.com/api/v4/.

  2. Ensure you have installed the correct GitLab provider. You can do this by running the following command in the directory where your .tf files are located:

    terraform init
    
  3. After setting the correct values and making sure everything is correctly set up, apply your configuration by running:

    terraform apply
    
  4. If you have sensitive data like tokens, it’s not recommended to put the real values directly in the scripts or code. Use secrets management tools to handle such information.

  5. Check your GitLab token permissions. It should have the necessary permissions for the operations you are trying to perform.

I could also suggest going over the official documentation here:

https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.