Problem
When referencing a module from a private GitHub repository using an SSH address like git::ssh://git@github.com/<username>/<repo-name>.git, Terraform Enterprise (TFE) runs fail with the following error:
ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Cause
This error occurs when the SSH key used for authentication is not correctly configured between the Terraform Enterprise instance and the private GitHub repository that hosts the module.
Solution
To resolve this issue, you must generate a dedicated SSH key pair and configure the private key in Terraform Enterprise and the public key in the GitHub repository.
Procedure
-
Generate a new SSH key pair in PEM format. This format is required for Terraform Enterprise. Replace the placeholder file path with your desired location.
$ ssh-keygen -t rsa -m PEM -f "/Users/<NAME>/.ssh/service_terraform" -C "service_terraform_enterprise"
- Add the generated private key to your Terraform Enterprise instance. Navigate to your workspace settings and add the private key as an SSH key.
- Add the corresponding public key to the private GitHub repository that hosts the module.
- In GitHub, navigate to your repository's Settings > Deploy Keys.
- Click Add Deploy Key.
- Provide a title for the key, paste the public key content, and select Allow write access if your workflow requires it.
- Click Add key to save.
Outcome
After you configure the SSH keys correctly in both Terraform Enterprise and the source repository, Terraform will be able to authenticate successfully and source the private modules during runs.
Additional Information
For more details on managing SSH keys for module cloning, refer to the documentation on how to use SSH keys for cloning modules.