Problem
After upgrading Bitbucket Server to version 8.18.0, Terraform runs fail during initialization with an error indicating it cannot download a module from a Bitbucket repository.
fatal: could not read Username for 'http://bitbucket_server_url': No such device or address
Prerequisites
- You are using Terraform Enterprise integrated with Bitbucket Server.
- You have administrative access to the Bitbucket server.
- Your Bitbucket Server version is 8.18.0 or newer.
Cause
Bitbucket Server version 8.18.0 disables anonymous public access for repositories by default. If your Terraform module source is configured to use an http URL, the Git clone operation fails because it can no longer access the repository without authentication, resulting in the prompt for a username that fails in a non-interactive environment.
Solution
To resolve this issue, you must update your Terraform configuration to use SSH for cloning the module source and ensure Terraform Enterprise has the necessary SSH key.
Procedure
-
Verify SSH Connectivity
Confirm that network communication is allowed on port 22 between your Terraform Enterprise instance and your Bitbucket server.
-
Add SSH Key to Terraform Enterprise
Add an SSH private key to the relevant Terraform Enterprise workspace. This key must be authorized to access the module repository in Bitbucket.
-
Update Module Source Configuration
Modify your Terraform configuration (
.tffiles) to use the SSH protocol for the module source URL. The URL should be in the formatgit::ssh://....For example, change a URL like this:
module "vpc" { source = "git::http://bitbucket_server_url/scm/project/repo.git?ref=v1.0.0" # ... }To a URL that uses the SSH format:
module "vpc" { source = "git::ssh://git@bitbucket_server_url/scm/project/repo.git?ref=v1.0.0" # ... }
Outcome
After applying these changes, Terraform will use SSH to authenticate with Bitbucket, allowing it to successfully download the module and proceed with the run.