0
votes

I am running a terragrunt script through the ansible play using the ansible shell module.

Ansible task

environment:
        AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}"
        AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}"
        AWS_DEFAULT_REGION: "{{aws_region}}"  
        AWS_SESSION_TOKEN: "{{aws_session_token}}"
  shell: "{{command}}" 

Here I am giving the command as an argument, its look like

terragrunt plan --terragrunt-working-dir /workspace/terraform/vpc

Inside my terragrunt script, some terraform modules are referring from private a Github repo and its should be downloaded as part of the command execution.

terraform {
    source = "git::https://<accesstoken>@<domanian>/vpc.git?ref=v0.2.0"
  }  

But when I run the ansible role I am getting authentication error from the git, but the repo cloning in the host machine works fine (No authentication issues).

I am having the git authentication issue from the ansible play not from the host machine(For now my host is localhost)

ERROR FROM TERRAGRUNT

error downloading 'https://<token>@<domain>/repo.git?ref=v0.7.0': /usr/local/bin/git exited with 128: Cloning into '/Users/<name>/Projects/terraform/integration/hli/eks/.terragrunt-cache/odeTjZcnAck1LSD4uQ9-Wn_30cQ/xBn6R6SbWXfZ6nabGc-LFpX6RXk'...
fatal: Authentication failed for 'https://<token>@<domain>/repo.git/'
1
Please include the actual error output you are experiencing, since the details matter, as does the indentation in your code snippetmdaniel
@mdaniel added error log(Removed the sensitive contents like repo access token,domain)iam batman

1 Answers

0
votes

Using SSH is suggested when connecting to private Git repositories.

Reference: https://terragrunt.gruntwork.io/docs/features/keep-your-terraform-code-dry/#using-terragrunt-with-private-git-repos

So in your example, it would be something like this. Notice the double // after the repository URL.

terraform {
  source = "git::ssh://[email protected]/foo/modules.git//path/to/module?ref=v0.2.0"
}