从TF 0.11升级到0.12后的Terraform错误无效计数参数

问题描述

从0.11升级到0.12后,由于依赖关系,某些东西在开始失败之前就起作用了

Error: Invalid count argument
  on ../modules/app-web/fargate.tf line 289,in resource "aws_security_group_rule" "proxy2target_group_1":
 289:   count                    = var.allow_security_group_id == "" ? 0 : 1
The "count" value depends on resource attributes that cannot be determined
until apply,so Terraform cannot predict how many instances will be created.
To work around this,use the -target argument to first apply only the
resources that the count depends on.

这实际上取决于另一种资源:allow_security_group_id = module.repl-ssm-tunnel-proxy.this_security_group_id 但是,实际上是找到所有此类资源并使用-target多次运行TF的唯一解决方案吗?为什么以前能奏效?我可以在不运行多个TF的情况下使其运行吗?

更新:我尝试了建议的解决方案,运行了terraform apply -target=aws_codepipeline.codepipeline_prod -target=aws_codepipeline.codepipeline_stage_from_github -target=aws_codepipeline.codepipeline_stage_from_ecr -target=module.repl-ssm-tunnel-proxy -target=module.direct-connect.aws_route_tables.private,但没有失败,但是也没有应用任何东西。也许因为所有这些都在模块内部(即production.tf-> modules / myapp-> modules / helper-XY),并且因为我没有针对顶级模块(myapp)而没有应用? 当然,如果我尝试添加顶级模块,由于原始计数问题,它再次失败:terraform apply ... -target=module.direct-connect.aws_route_tables.private -target module.direct_connect赶上22吗? :-(

解决方法

从0.12升级到0.13消除了许多这样的警告,其余的警告很容易通过更改代码来解决。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...