Introduction
Terraform Cli does version/source constraint processing separately from the .tfvar*
defined variables on the init and plan stage.
Problem
When trying to use variables for source or version when calling a module the following error is returned:
Unsuitable value: value must be known
Cause
This issue is caused when attempting to use a variable for source and/or version when calling a module.
Example code:
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
}
Solution
When calling a module the version and source must be a known value as terraform cli does not process variable values on the init and plan stage.
To make it work define version constraint and module source in the Terraform configuration explicitly.
Example code:
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 rules apply to the Terraform configuration block