在一开始,我只想构建一台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]
答案 0 :(得分: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}"
}