I have the following code in Terraform:
resource "aws_db_instance" "replica_rds_instance" {
for_each = var.rds_number_of_replicas //integer
//something
}
But I receive the following error:
The given "for_each" argument value is unsuitable: the "for_each" argument
must be a map, or set of strings, and you have provided a value of type
number.
The var must be a number. I also tried to use toset(range(var.rds_number_of_replicas)) but I found another error:
The given "for_each" argument value is unsuitable: "for_each" supports maps
and sets of strings, but you have provided a set containing type number.
3
Answers
Based on Matthew`s post I used:
If you really want to use
for_each
with a variable of typenumber
, then you can do an iterative type conversion with afor
expression within alist
constructor within aset
type converter:But also it would fit naturally with the
count
meta-parameter as described in the answer posted by MarkoE simultaneous with this answer.Even though I feel information is lacking in the question, I think the better option here is to use the
count
meta-argument: