Problem
When you use variables for the source or version arguments in a module block, Terraform returns the following error during the init or plan stage.
Unsuitable value: value must be known
This issue occurs with configuration similar to the following example.
variable "bucket_name" {
default = "just-another-bucket-20220216"
}
variable "module_source" {
default = "terraform-aws-modules/s3-bucket/aws"
}
variable "module_version" {
default = "2.14.1"
}
module "aws_s3_bucket" {
source = var.module_source
version = var.module_version
bucket = var.bucket_name
}Cause
The source and version arguments for a module must be literal string values known at the beginning of a Terraform run. During the init phase, Terraform downloads and caches modules before it fully evaluates variables from .tfvars files or other sources. Because the values for var.module_source and var.module_version are not yet known when Terraform needs to locate the module, the operation fails.
Solution
To resolve this issue, you must define the module source and version arguments with explicit, literal string values in your Terraform configuration.
Here is the corrected configuration.
variable "bucket_name" {
default = "just-another-bucket-20220216"
}
module "aws_s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "2.14.1"
bucket = var.bucket_name
}Additional Information
The same requirement for literal string values applies to arguments within the main terraform configuration block.
- For more details, refer to the Terraform configuration block documentation.