Answers: <p>There is a clue in your error message, but it's only helpful if you know what you're looking for:</p>
  
  <pre><code>    | module.mongodb.instance_names is tuple with 1 element
      | module.mongodb.private_ip is list of string with 1 element
  </code></pre>
  
  <p>Your declaration of the <code>instance_names</code> output includes this expression:</p>
  
  <pre><code>["${data.template_file.instance_tags_name.*.rendered}"]
  </code></pre>
  
  <p>The <code>data.template_file.instance_tags_name.*.rendered</code> part of this returns a list of strings, and then the <code>[ ... ]</code> 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 <code>count</code> instances.</p>
  
  <p>This situation is what the upgrade guide discusses under <a href="https://www.terraform.io/upgrade-guides/0-12.html#referring-to-list-variables" rel="nofollow noreferrer">Referring to List Variables</a>, and that documentation includes some more background information on why this previously worked in 0.11 and why the change is required now.</p>
  
  <p>To fix this, you should refer to just the splat expression alone, producing the flat list of strings that your <code>formatlist</code> call is expecting:</p>
  
  <pre><code>output "instance_names" {
    value = data.template_file.instance_tags_name.*.rendered
  }
  </code></pre>
  
  <p>The automatic configuration upgrade tool described in <a href="https://www.terraform.io/upgrade-guides/0-12.html" rel="nofollow noreferrer">the upgrade guide</a> 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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-08-23T17:54:57.213Z
Answers: 2019-08-23T17:54:57.213Z
Answers: Martin Atkins
Body: <p>After upgrading to 0.12 I receive a lots of error like:</p>
  
  <pre><code>Error: Error in function call
  
    on main.tf line 136, in data "template_file" "inventory":
   136:       formatlist(
   137:
   138:
   139:
   140:
      |----------------
      | 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.
  </code></pre>
  
  <p>Here is from my main.ft:</p>
  
  <pre><code>connection_strings_mongodb_standalone = join(
        "\n",
        formatlist(
          "%s ansible_host=%s ansible_user=ubuntu",
          module.mongodb.instance_names,
          module.mongodb.private_ip,
        ),
  </code></pre>
  
  <p>And module:</p>
  
  <pre><code>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
      },
      var.default_tags,
    )
    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
  }
  </code></pre>
  
  <p>from ../modules/mongodb output.tf:</p>
  
  <pre><code>output "instance_names" {
    value = [
      "${data.template_file.instance_tags_name.*.rendered}",
    ]
  }
  </code></pre>
  
  <p>As I correct understend need to set type of output value, but can't find how, hope someone can help me.
  Thanks in advance.</p>
  
Tags: <terraform>
Title: Terraform | After upgrading to 0.12 receive a lots of error "unsupported value for "%s" at 0: string required."
UserDisplayName: Stailas
ThreadText: # Terraform | After upgrading to 0.12 receive a lots of error "unsupported value for "%s" at 0: string required."
  
  (Asked by: username_0 on 2019-08-23)
  
  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(
   137:
   138:
   139:
   140:
      |----------------
      | 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(
        "\n",
        formatlist(
          "%s ansible_host=%s ansible_user=ubuntu",
          module.mongodb.instance_names,
          module.mongodb.private_ip,
        ),
  
  ```
  
  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
      },
      var.default_tags,
    )
    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 = [
      "${data.template_file.instance_tags_name.*.rendered}",
    ]
  }
  
  ```
  
  As I correct understend need to set type of output value, but can't find how, hope someone can help me.
  Thanks in advance.
  
  **Tags:** terraform
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-08-23. Score: 3 | Accepted answer
  
  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:
  
  ```
  ["${data.template_file.instance_tags_name.*.rendered}"]
  
  ```
  
  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](https://www.terraform.io/upgrade-guides/0-12.html#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](https://www.terraform.io/upgrade-guides/0-12.html) 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.
  
  
  ---
  
  