【发布时间】:2021-12-04 13:00:27
【问题描述】:
当我使用 for_each 创建时如何获取我的模块 ec2 的实例 ID,并且我需要我的模块 tgroup 的 instance_id 来分配或加入特定目标组中的新实例。
我的模块 ec2
resource "aws_instance" "ProductionServer" {
count = length(var.SubnetServer)
ami = module.CreateAMI.AMIId.id
instance_type = var.TypeServer
subnet_id = var.SubnetServer[count.index]
}
ec2/outputs.tf
output "InstanceId" {
value = aws_instance.ProductionServer
description = "get value id"
}
和我的模块 tgroup
resource "aws_alb_target_group_attachment" "TgProdRegister" {
for_each = module.GetInstanceId.InstanceId.id
target_group_arn = var.TgroupArn
target_id = each.value
port = var.TgPort
depends_on = [ module.GetInstanceId ]
}
和 GetInstanceId 是指模块 ec2
【问题讨论】:
标签: amazon-web-services terraform terraform-provider-aws