Skip to content

Opentofu modules

Use module from git branch

URL Structure:

git::<protocol>://<host>/<repo>.git//<subdir>?ref=<branch|tag|commit>
source = "git::https://github.com/your-org/terraform-modules.git//modules/s3_bucket?ref=v1.2.0"

Issues

could not read Username for 'https://gitlab.com' in Gitlab CI:

Could not download module "folder" (folder.tofu:1) source code from
│ "git::https://gitlab.com/…/managed-folder.git?ref=test_branch":
│ error downloading
│ 'https://gitlab.com/…/managed-folder.git?ref=test_branch':
│ /usr/bin/git exited with 128: Cloning into '.terraform/modules/folder'...
│ fatal: could not read Username for 'https://gitlab.com': No such device or
│ address

Add authentication to Gitlab in .gitlab-ci.yml:

validate:
  before_script:
    - git config --global credential.helper store
    - echo "https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com" > ~/.git-credentials # pragma: allowlist secret
plan:
  before_script:
    - git config --global credential.helper store
    - echo "https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com" > ~/.git-credentials # pragma: allowlist secret