"No space left on device" Error During Runs in HCP Terraform
Problem
During a run in HCP Terraform, you may encounter an error similar to the following, indicating that the ephemeral execution environment has run out of disk space.
╷│ Error: Failed to download module │ │ '.terraform/modules/XXX': No space left on device ╵
Cause
This error can be caused by a known issue in the Terraform binary that occurs when all of the following conditions are met in your configuration:
- Two or more Terraform modules have an identical value for the
sourceargument. - The modules use the SSH protocol in the
sourcevalue (e.g.,git@github.com:...). - One of the identically-sourced modules is missing a name for its configuration block.
This combination of conditions can cause the Terraform binary to enter an erroneous state, consuming all available disk space in the run environment before it can report the actual configuration error of the missing module name.
This issue is known to occur in Terraform version 1.1.6 but may also affect other versions.
Solutions
Solution 1: Correct the Unnamed Module Block
The resolution is to identify and correct the module block that is missing a name in your Terraform configuration.
For example, an incorrect configuration might look like this:
## Incorrect configuration with a missing name for the second module block
module "vpc" {
source = "git@github.com:company/modules.git//vpc"
## ...
}
module { ## This block is missing a name
source = "git@github.com:company/modules.git//vpc"
## ...
}To fix this, provide a unique name for the unnamed module block.
## Correct configuration with unique names for both module blocks
module "vpc" {
source = "git@github.com:company/modules.git//vpc"
## ...
}
module "vpc_secondary" { ## This block now has a unique name
source = "git@github.com:company/modules.git//vpc"
## ...
}After correcting the configuration, commit the changes to your version control system to trigger a new run in HCP Terraform.