Skip to content

Gitlab private Registry Authentication #102

@Robin-Walter

Description

@Robin-Walter

I will use an existing private gitlab Terraform Module Registry to create AWS Resources. AWS Resources works fine. Only the connection to the gitlab Terraform Modul Registry wouldn't work.
I try tofu.rc as secret, TF_TOKEN as Token only with different Urls and Sources.

My current configuration is:

apiVersion: opentofu.m.upbound.io/v1beta1
kind: Workspace
metadata:
  name: sample-inline-2
  namespace: crossplane-system
spec:
  forProvider:
    env:
      - name: "TF_TOKEN_private_gitlab_domain"
        value: ""
    module: https://private_gitlab_domain/folder/terraform_modul/dev
    source: Remote
    vars:
      - key: "variable1"
        value: "[\"folder1\", \"folder2\"]"
  providerConfigRef:
    kind: ProviderConfig
    name: default

and the configuration

apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: upbound-provider-opentofu
spec:
  package: xpkg.upbound.io/upbound/provider-opentofu:v1
---
apiVersion: opentofu.m.upbound.io/v1beta1
kind: ProviderConfig
metadata:
  name: default
  namespace: crossplane-system
spec:
  configuration: |
    // Modules _must_ use remote state. The provider does not persist state.

    terraform {
      backend "kubernetes" {
        secret_suffix     = "providerconfig-default"
        namespace         = "crossplane-system"
        in_cluster_config = true
      }
      required_providers {
        aws = {
          source = "hashicorp/aws"
        }
      }
    }
    provider "aws" {
      region = "eu-central-1"
      shared_credentials_files = ["${path.module}/credentials"]
    }
  credentials:
    - filename: credentials
      secretRef:
        key: creds
        name: aws-secret
        namespace: crossplane-system
      source: Secret
    - filename: tofu.rc
      secretRef:
        namespace: crossplane-system
        name: tofurc
        key: tofu.rc
      source: Secret

When i am working with hardcoded Url like:
module: "git::https://username:token:@private_gitlab_domain/terraform_modul.git//folder?ref=dev"
it work's.
But this is not the Terraform Modul Registry in our Private Repo, it's the Gitlab Repository.

When i am using as Modul Source
"private_gitlab_domain/..."
the error occured:
file:///tofu/616591dc-a │
│ f53-4659-82e8-1f73cc8caa76/private_gitlab_domain/terraform_modul.git//folder?ref=dev': source path error: stat /tofu/61659 │
│ 1dc-af53-4659-82e8-1f73cc8caa76/private_gitlab_domain/terraform_modul.git//folder?ref=dev: no such file or directory

When i am using as Modul Source
"https://private_gitlab_domain..." the Username is expected

I am using the Token Variable and also the tofurc File.
How can a use gitlab Terraform Module Registries with Authentication?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions