我正在升级到 terraform 12 并有一个引用根存储库的 asg 模块。作为其中的一部分,它使用data.template_file资源将用户数据附加到 asg,然后将其放入实例上的日志文件中。该模块如下所示;
module "cef_fleet" {
source = "git::ssh://git@github.com/asg-repo.git?ref=terraform12"
user_data_rendered = data.template_file.init.rendered
instance_type = var.instance_type
ami = var.ami
etc ...
如您所见,它调用了数据资源;
data "template_file" "init" {
count = signum(var.cluster_size_max)
template = file("${path.module}/template-files/init.sh")
vars = {
account_name = var.account_name
aws_account_number = var.aws_account_number
这在 terraform 11 中运行良好,但是当我更改为 terraoform 12 并尝试应用时,我收到此错误:
*Because data.template_file.init has "count" set, its attributes must be
accessed on specific instances.
For example, to correlate with indices of a referring resource, use:
data.template_file.init[count.index]*
如果我在我的模块中将其更改为user_data_rendered = data.template_file.init[count.index] 我会收到此错误;
The "count" object can be used only in "resource" and "data" blocks, and only
when the "count" argument is set.
我不知道在这里做什么。如果我将 .rendered 留在其中,那么当我再次遇到第一个错误时,它似乎无法识别 [count.index]。有人对我需要做什么有任何建议吗?