How to fix “rsadecrypt: argument 1 should be type string, got type list in:”

心已入冬 提交于 2019-12-13 03:45:15

问题


At the beginning I want to build just one windows machine, so this code works fine at the beginning:

output "Administrator_Password" {
  value = "${rsadecrypt(aws_instance.new_instance.password_data, file("${module.ssh_key_pair.private_key_filename}"))}"
}

But once I introduce count to resource "aws_instance" "new_instance" {, I have to add * to the expression aws_instance.new_instance.*.password_data.

But then I start to get this error:

Error: Error running plan: 1 error(s) occurred:

* output.Administrator_Password: At column 3, line 1: rsadecrypt: argument 1 should be type string, got type list in:

${rsadecrypt(aws_instance.new_instance.*.password_data, file("${module.ssh_key_pair.private_key_filename}"))}

I have tried the count.index syntax but they do not work. The variants are

aws_instance.new_instance.password_data[count.index]

and

aws_instance.new_instance.password_data[aws_instance.new_instance.count.index]

回答1:


Try to use template_file resource,

data "template_file" "decrypted_keys" {
  count = "${aws_instance.new_instance.count}"

  template = "${rsadecrypt(element(aws_instance.new_instance.*.password_data, count.index), file(module.ssh_key_pair.private_key_filename))}"
}

output "Administrator_Password" {
  value = "${data.template_file.decrypted_keys.*.rendered}"
}


来源:https://stackoverflow.com/questions/56884621/how-to-fix-rsadecrypt-argument-1-should-be-type-string-got-type-list-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!