1. Help Center
  2. Troubleshooting

I want to use a module from a private git repository, How can I pass an SSH key for terraform?

If you have a terraform module in another private git repository, you need to tell terraform which SSH key it should use, here's how to do so

To resolve that issue, you need to pass the SSH key as an environment variable, this environment variable can and should be marked as sensitive. In this case, we call it "SSH_PRIVATE_KEY", with minor adjustments

Usually, SSH keys look like this - 

————-
Somehexcode
Anotherhexhere
Yetanotherone
——-

When you paste it as an env0 variable, replace new lines with ;

———Somehexcode;Anotherhexhere;Yetanotherone——-

Then use this env0.YAML

deploy:
steps:
terraformInit:
before:
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr ';' '\n' | tr -d "\r" > ~/.ssh/private_tf_modules
- chmod 400 ~/.ssh/private_tf_modules
- echo -e "Host github.com\n User git\n Hostname github.com\n IdentityFile ~/.ssh/private_tf_modules\n StrictHostKeyChecking no" > ~/.ssh/config
- echo "Created private key"

Then, we tell Linux when we want to SSH to github.com to use this SSH file.