[英]How to get multiple values in a list without using count in terraform?
I am creating multiple resources using count in terraform.我正在使用 terraform 中的计数创建多个资源。 for ex:例如:
resource "aws_subnet" "rSubnetMGMT" {
count = length(var.vletter)
availability_zone = "${var.vRegion}${var.vletter[count.index]}"
vpc_id = aws_vpc.rVPCMGMT.id
cidr_block = var.vSubnetMGMTCIDR
map_public_ip_on_launch = "true"
tags = {
Name = "${var.vWorkloadShortCode}-mgmt-MGMT- ${var.vRegion}${var.vletter[count.index]}"
SubnetType = "MGMT"
}
}
here vletter = ["a","b","c"] so this creates 3 subnets per availability zone now I want to create an "aws_autoscaling_group" which requires a list of vpc_zone_identifier ie the subnet ids that I created这里 vletter = ["a","b","c"] 所以这会为每个可用区创建 3 个子网,现在我想创建一个“aws_autoscaling_group”,它需要一个 vpc_zone_identifier 列表,即我创建的子网 ID
resource "aws_autoscaling_group" "rAutoScalingGroup" {
count = lenght(var.vletter)
max_size = var.vMaxNoofInstances
min_size = var.vMinNoofInstances
launch_configuration = aws_launch_configuration.rLaunchConfiguration.name
vpc_zone_identifier = [aws_subnet.rSubnetMGMT[count.index].id ]
metrics_granularity = 1Minute
enabled_metrics = [GroupInServiceInstances]
load_balancers = aws_elb.rLoadBalancer.name
tag {
Name = "${var.vInstanceShortNameBAS}-asg"
}
}
but if I use count while creating the resource(aws_autoscaling_group) it will create multiple resources ie 3 different autoscaling groups for each subnet, but here I only want all the subnet ids that I created earlier.但是如果我在创建资源 (aws_autoscaling_group) 时使用计数,它将为每个子网创建多个资源,即 3 个不同的自动缩放组,但在这里我只想要我之前创建的所有子网 ID。 How can I achieve this without creating multiple resources?如何在不创建多个资源的情况下实现这一目标?
您可以使用 splat 运算符: aws_subnet.rSubnetMGMT.*.id
,它将解析为所创建子网的 ID 列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.