【问题标题】:How to fix "rsadecrypt: argument 1 should be type string, got type list in:"如何修复“rsadecrypt:参数 1 应该是类型字符串,类型列表在:”
【发布时间】:2019-11-14 23:59:35
【问题描述】:

一开始我只想构建一台windows机器,所以这段代码一开始就可以正常工作:

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

但是一旦我将count 引入resource "aws_instance" "new_instance" {,我必须将* 添加到表达式aws_instance.new_instance.*.password_data

但随后我开始收到此错误:

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}"))}

我尝试了count.index 语法,但它们不起作用。变种是

aws_instance.new_instance.password_data[count.index]

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

【问题讨论】:

标签: terraform


【解决方案1】:

尝试使用template_file资源,

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}"
}

【讨论】:

    猜你喜欢
    • 2020-01-18
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    相关资源
    最近更新 更多