Posted on ::

Git setup for terraform

Terraform modules from private GitLab repositories require authentication. The same URL rewriting approach used for Cargo setup for private Rust dependencies on GitLab solves this.

Solution

Configure git to rewrite HTTPS URLs to include credentials:

git config --global url."https://ID:[email protected]".insteadOf "https://gitlab.com"

Or add directly to ~/.gitconfig:

[url "https://ID:[email protected]"]
    insteadOf = https://gitlab.com

Replace ID with your GitLab user ID and TOKEN with a personal access token that has read_repository scope.

Verification

Test the configuration:

terraform init
terraform plan

The modules should now download successfully from private repositories.

Table of Contents