debugterraformMinor
Terraform | After upgrading to 0.12 receive a lots of error "unsupported value for "%s" at 0: string required."
Viewed 0 times
afterunsupportederrorupgradingvaluelotsreceiveforstringrequired
Problem
After upgrading to 0.12 I receive a lots of error like:
Here is from my main.ft:
And module:
from ../modules/mongodb output.tf:
As I correct understend need to set type of output value, but can't find how, hope someone can help me.
Thanks in advance.
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.
Solution
There is a clue in your error message, but it's only helpful if you know what you're looking for:
Your declaration of the
The
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
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.
| module.mongodb.instance_names is tuple with 1 element
| module.mongodb.private_ip is list of string with 1 elementYour 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, 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.
Code Snippets
| module.mongodb.instance_names is tuple with 1 element
| module.mongodb.private_ip is list of string with 1 element["${data.template_file.instance_tags_name.*.rendered}"]output "instance_names" {
value = data.template_file.instance_tags_name.*.rendered
}Context
StackExchange DevOps Q#8977, answer score: 3
Revisions (0)
No revisions yet.