terraform在模块中使用计数索引
我想在我的aws ec2实例的terraform模块中使用count.index以递增顺序命名该实例terraform在模块中使用计数索引,terraform,terraform-provider-aws,Terraform,Terraform Provider Aws,我想在我的aws ec2实例的terraform模块中使用count.index以递增顺序命名该实例 file: ec2/main.tf resource "aws_instance" "instance"{ ami = "ami-xxx" tags { Name = "var.instance" } count = "var.count" } 我希望实例名称填充为 firsttypeinstance-1 第一类实例-2 第一类实例-3 第二类
file: ec2/main.tf
resource "aws_instance" "instance"{
ami = "ami-xxx"
tags {
Name = "var.instance"
}
count = "var.count"
}
我希望实例名称填充为
firsttypeinstance-1
第一类实例-2
第一类实例-3
第二类-1
第二类-2
但是我得到一个错误,我不能在模块中使用计数索引
:
除上述内容外,Terraform当前未使用参数名称count
、每个参数的和lifecycle
,但保留用于计划的未来功能
但是,您可以在模块中创建my_count
变量,并在模块内的资源上使用它
模块ec2
资源“aws\u实例”“实例”{
ami=“ami xxx”
标签{
Name=“var.instance-${count.index}”
}
count=“var.my\u count”
}
主模块
模块“ec2”{
source=“./ec2”
我的计数=3
实例_name=“firsttypeinstance”##实际上是实例前缀
}
file: ec2instance.tf
module "ec2"{
source = "./ec2"
count = 3
instance_name = "firsttypeinstance-${count.index+1}"
}
module "ec20"{
source = "./ec2"
count = 2
instance_name = "secondtype-${count.index+1}"
}