我正在尝试获取在 vpc 模块中创建的 elastic_ip ID,并将其传递给 trasnfer 系列模块,以在面向 Internet 的 VPC 中部署 AWS trasnfer 系列服务器。
所以我正在创建两个弹性 IP,每个子网一个。 (有两个子网)
resource "aws_vpc_endpoint" "aws_trasnfer_server" {
vpc_id = aws_vpc.shared_services_vpc.id
service_name = "com.amazonaws.${var.aws_region}.transfer.server"
subnet_ids = ["${aws_subnet.public_subnet_2a.id}", "${aws_subnet.public_subnet_2b.id}"]
security_group_ids = ["${aws_default_security_group.default.id}"]
vpc_endpoint_type = "Interface"
}
locals {
network_interfaces = aws_vpc_endpoint.aws_trasnfer_server.network_interface_ids
# private_id = aws_vpc_endpoint.aws_trasnfer_server.network_interface_ids
}
resource "aws_eip" "subnet_eips_one" {
for_each = local.network_interfaces
vpc = true
}
上面的代码工作正常,但我无法导出 elastic_ip ID 并传递给 trasnfer 模块。 这是 vpc 模块的 output.tf
output "elastic_ips" {
value = toset(values(aws_eip.subnet_eips_one[*].id))
# aws_security_group.example.*.id
}
运行脚本时出现以下错误
╷
│ Error: Unsupported attribute
│
│ on vpc/outputs.tf line 19, in output "elastic_ips":
│ 19: value = toset(values(aws_eip.subnet_eips_one[*].id))
│
│ This object does not have an attribute named "id".
我可以看到
的输出toset(values(aws_eip.subnet_eips_one))
如下和错误。
elastic_ips = [
- "eni-012334567899",
- "eni-023568765465",
+ {
+ address = null
+ allocation_id = "eipalloc-0aaaaaaaaaaaa"
+ associate_with_private_ip = null
+ association_id = ""
+ carrier_ip = ""
+ customer_owned_ip = ""
+ customer_owned_ipv4_pool = ""
+ domain = "vpc"
+ id = "eipalloc-0aaabbbbbbbb"
+ instance = ""
+ network_border_group = "us-west-2"
+ network_interface = ""
+ private_dns = null
+ private_ip = ""
+ public_dns = "ec2-00-00-00.00.us-west-2.compute.amazonaws.com"
+ public_ip = ""
+ public_ipv4_pool = "amazon"
+ tags = {}
+ tags_all = {}
+ timeouts = null
+ vpc = true
},
+ {
+ address = null
+ allocation_id = "eipalloc-ccccc"
+ associate_with_private_ip = null
+ association_id = ""
+ carrier_ip = ""
+ customer_owned_ip = ""
+ customer_owned_ipv4_pool = ""
+ domain = "vpc"
+ id = "eipalloc-dddddddd"
+ instance = ""
+ network_border_group = "us-west-2"
+ network_interface = ""
+ private_dns = null
+ private_ip = ""
+ public_dns = "ec2-00-00-00-00.us-west-2.compute.amazonaws.com"
+ public_ip = "00.0.0.0"
+ public_ipv4_pool = "amazon"
+ tags = {}
+ tags_all = {}
+ timeouts = null
+ vpc = true
},
]
│ Error: Incorrect attribute value type
│
│ on awstransfer/main.tf line 22, in resource "aws_transfer_server" "filetransfer_server":
│ 22: address_allocation_ids = var.elastic_ips
│ ├────────────────
│ │ var.elastic_ips is set of object with 2 elements
│
│ Inappropriate value for attribute "address_allocation_ids": incorrect set element type: string required.
我尝试了多种选择,但无法准确获取 ID 并将其传递给输出变量。
我错过了什么吗?预先感谢您的帮助。
谢谢。
你的一个
)
位置不对。另外你真的不需要toset
。所以应该是:
value = values(aws_eip.subnet_eips_one)[*].id