如何解决Terraform 0.11-模拟循环
我有Terraform 0.11.14 ,并努力模拟Terraform 0.12的for
循环。
我想解密AWS EC2 Windows实例密码并将其放在terraform输出中。为此,我需要:
- 获取EC2实例密钥文件名列表
- 构建密钥文件路径列表
- 获取EC2实例的列表password_data
- 对于每个EC2实例password_data,使用各自的密钥文件运行解密
main.tf
resource "aws_instance" "this" {
count = "${var.can_create ? (var.instance_count > 1 ? var.instance_count : 1) : 0}"
get_password_data = "${var.get_password_data}"
...
}
variables.tf
variable "can_create" {
description = "If false,instance is not going to be created"
type = "string"
default = "true"
}
variable "instance_count" {
description = "Number of instances to launch"
default = 1
}
variable "get_password_data" {
description = "If true,wait to retrieve password for Windows instances"
default = "true"
}
...
output.tf
locals {
this_key_name = "${aws_instance.this.*.key_name}"
this_key_path = "${formatlist("/root/.ssh/%s",local.this_key_name)}"
this_password_data = [for p in local.this_key_path : rsadecrypt(aws_instance.this.*.password_data,file(p))] #this does not work
}
output "password_data" {
description = "List of passwords for Windows instances"
value = ["${local.this_password_data}"]
}
特别是如何模拟this_password_data
变量中的循环?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。