Is it possible to concat lists produced by formatlist? The following gives the error
At column 1, line 1: output of an HIL expression must be a string, or a single list (argument 6 is TypeList)
:
{
"Action": [
"s3:Get*",
"s3:List*"
],
"Effect": "Allow",
"Resource": ["${concat(
formatlist("arn:aws:s3:::%s", ${var.data_pipeline_s3_buckets}),
formatlist("arn:aws:s3:::%s/*", ${var.data_pipeline_s3_buckets}))}"]
},
It looks like you're trying to build a JSON array here, in which case something like the following should work:
{
"Action": [
"s3:Get*",
"s3:List*"
],
"Effect": "Allow",
"Resource": ${jsonencode(
concat(
formatlist("arn:aws:s3:::%s", var.data_pipeline_s3_buckets),
formatlist("arn:aws:s3:::%s/", var.data_pipeline_s3_buckets)
)
)}
}
Your original example has a few parts that are problematic here:
${ ... }
sequence you can't use a second ${
delimiter. This marker signals the transition from string context into interpolation expression context, so it's not valid when you're already in interpolation expression context.jsonencode
in the above example, thus turning the list into a string before returning it.That error message means that you are providing a list where you should be providing a string.
$concat doesn't do what I think you think it does; it does not concatenate the items in a list to form a string, it concatenates two lists to form another list.
You need to use $join instead.
I have a worked example at http://thecloudwoman.com/2017/05/how-to-use-a-terraform-list-variable/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With