Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab Terraform module init /authentication issue

Currently having an issue pulling my own module from a gitlab terraform module registry. Gone through the gitlab documentation but still struggling. Gone with the instructions and using the following config:

module "ResourceGroup" {
  source = "gitlab.com/<myuser>/resourcegroupmodule/mysystem"
  version = "0.0.1"
  
  base_name = "TerraformExample01"
  location = "West US"
}

When i try and run terraform init, I get the following error:

│ Error: Error accessing remote module registry
│ 
│ Failed to retrieve available versions for module "ResourceGroup" (main.tf:25) from gitlab.com: error looking up module versions:
│ 401 Unauthorized.

Tried to add a credential block as per the instructions but no success either. Added this block to the main.tf file:

credentials "gitlab.com" {
  token = "<myAPIkey>"
}

Any help greatly appreciated. Feels like kind of got the credentials section/api token in the wrong place.

like image 731
John Fox Avatar asked May 13 '26 11:05

John Fox


2 Answers

I used environment variable TF_TOKEN_gitlab_whatever_domain_com= Access toke with read_api permission. I have a hosted gitlab solution on gitlab.whatever.domain.com This approach worked for me.

like image 154
Ruslan Kovalov Avatar answered May 16 '26 03:05

Ruslan Kovalov


The answer is above from @lyzlisa.

Just created the ~/.terraformrc file with the credentials block

like image 23
John Fox Avatar answered May 16 '26 03:05

John Fox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!