Azure DevOps use module from another repository in different project

Viewed 1183

I have my coding project in Azure DevOps and I would like to use Terraform modules I create. However I would like to keep terraform and my application each in different project.

I am having issues when I want to use Terraform inside AZ Pipelines, I receive the following error when I run my pipeline:

  - task: Bash@3
    displayName: 'DEBUG'
    inputs:
      targetType: 'inline'
      script: |
        git config --get-all --global http.https://dev.azure.com/my-organization/Infra/_git/terraform-modules.extraheader "Authorization: bearer $SYSTEM_ACCESSTOKEN"
        terraform init
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)

Output

Error: Failed to download module

Could not download module "iam" (aws_ecs.tf:11) source code from
"git::https://dev.azure.com/my-organization/Infra/_git/terraform-modules": error
downloading 'https://dev.azure.com/my-organization/Infra/_git/terraform-modules':
/usr/bin/git exited with 128: Cloning into '.terraform/modules/iam'...
fatal: could not read Username for 'https://dev.azure.com': terminal prompts
disabled

Module source is configured like this:

  source = "git::https://dev.azure.com/my-organization/Infra/_git/terraform-modules//modules/ecs-iam"

AZ DevOps settings (images):

On the local machine, everything works fine, the module is cloned OK.

I have tried to follow the official guide https://www.terraform.io/docs/modules/sources.html

Is this even possible?

2 Answers

I think you have the wrong url in git config, You should remove everything after repository name.

It should look like:

git config --global http.https://dev.azure.com/my-organization/Infra.extraheader "Authorization: bearer $SYSTEM_ACCESSTOKEN"
Related