After upgrading to 0.12 I receive a lots of error like:

Error: Error in function call

  on main.tf line 136, in data "template_file" "inventory":
 136:       formatlist(
    | module.mongodb.instance_names is tuple with 1 element
    | module.mongodb.private_ip is list of string with 1 element

Call to function "formatlist" failed: error on format iteration 0: unsupported
value for "%s" at 0: string required.

Here is from my main.ft:

connection_strings_mongodb_standalone = join(
        "%s ansible_host=%s ansible_user=ubuntu",

And module:

module "mongodb" {
  source                      = "../modules/mongodb"
  instance_count              = "1"
  environment                 = var.env
  instance_type               = "i3.large"
  subnet_id                   = element(tolist(data.aws_subnet_ids.private.ids), 0)
  associate_public_ip_address = false
  vpc_id                      = data.aws_vpc.vpc.id
  tags = merge(
      "Environment" = var.env
  iam_instance_profile = var.iam_instance_profile
  route53_zone_id      = data.aws_route53_zone.zone.zone_id
  ami                  = var.ami

output "mongodb_private_ip" {
  value = module.mongodb.private_ip

output "tags" {
  value = module.mongodb.instance_names

from ../modules/mongodb output.tf:

output "instance_names" {
  value = [

As I correct understend need to set type of output value, but can't find how, hope someone can help me. Thanks in advance.

1 Answer 1


There is a clue in your error message, but it's only helpful if you know what you're looking for:

    | module.mongodb.instance_names is tuple with 1 element
    | module.mongodb.private_ip is list of string with 1 element

Your declaration of the instance_names output includes this expression:


The data.template_file.instance_tags_name.*.rendered part of this returns a list of strings, and then the [ ... ] around it then wraps an extra list (or rather, tuple) around it, creating a single-element tuple containing a list of strings. That's why the tuple contains only one element, rather than having an element for each of your count instances.

This situation is what the upgrade guide discusses under Referring to List Variables, and that documentation includes some more background information on why this previously worked in 0.11 and why the change is required now.

To fix this, you should refer to just the splat expression alone, producing the flat list of strings that your formatlist call is expecting:

output "instance_names" {
  value = data.template_file.instance_tags_name.*.rendered

The automatic configuration upgrade tool described in the upgrade guide can make this change automatically in some cases, so I'd recommend using that as a starting point for your 0.12 upgrade process. It isn't able to fix everything, but it will do a lot of the straightforward rewriting work for you and will emit warnings about some more complex situations it's unable to handle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.