Question

how to setup gitlab create repositories

this 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


Submit an answer


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!

Sign In or Sign Up to Answer

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.

KFSys
Site Moderator
Site Moderator badge
September 28, 2023

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel