-1

当我运行 terraform plan 时,出现以下错误:

Error: Reference to undeclared input variable
│ 
│   on .terraform/modules/ec2-datapipeline/main.tf line 5, in resource "aws_instance" "this":
│    5:   count = "${var.count}"
│ 
│ An input variable with the name "count" has not been declared. This
│ variable can be declared with a variable "count" {} block.
╵
╷
│ Error: Incorrect attribute value type
│ 
│   on .terraform/modules/ec2-datapipeline/main.tf line 13, in resource "aws_instance" "this":
│   13:   vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
│     ├────────────────
│     │ var.vpc_security_group_ids is a list of string, known only after apply
│ 
│ Inappropriate value for attribute "vpc_security_group_ids": element 0:
│ string required.
╵
╷
│ Error: Unsupported argument
│ 
│   on .terraform/modules/ec2-datapipeline/main.tf line 23, in resource "aws_instance" "this":
│   23:   root_block_device      = "${var.root_block_device}"
│ 
│ An argument named "root_block_device" is not expected here. Did you mean to
│ define a block of type "root_block_device"?
╵
╷
│ Error: Unsupported argument
│ 
│   on .terraform/modules/ec2-datapipeline/main.tf line 24, in resource "aws_instance" "this":
│   24:   ebs_block_device       = "${var.ebs_block_device}"
│ 
│ An argument named "ebs_block_device" is not expected here. Did you mean to
│ define a block of type "ebs_block_device"?
╵
╷
│ Error: Unsupported argument
│ 
│   on .terraform/modules/ec2-datapipeline/main.tf line 25, in resource "aws_instance" "this":
│   25:   ephemeral_block_device = "${var.ephemeral_block_device}"
│ 
│ An argument named "ephemeral_block_device" is not expected here. Did you
│ mean to define a block of type "ephemeral_block_device"?
╵
╷
│ Error: Error in function call
│ 
│   on .terraform/modules/ec2-datapipeline/main.tf line 36, in resource "aws_instance" "this":
│   36:   tags = "${merge(var.tags, map("Name", format("%s-%d", var.name, count.index+1)))}"
│     ├────────────────
│     │ count.index is a number, known only after apply
│     │ var.name will be known only after apply
│ 
│ Call to function "map" failed: the "map" function was deprecated in
│ Terraform v0.12 and is no longer available; use tomap({ ... }) syntax to
│ write a literal map.

当我将它们修复.terraform/modules/main.tfvariables.tf归档时,计划成功,并且当我从 CLI 触发时它通过了。但是,当我从 UI 触发计划时实际推送代码时,它不起作用。

所以,当我这样做时terraform init --upgrade。它恢复正常,我可以看到同样的问题。

你能帮我解决这个问题吗?谢谢!

4

1 回答 1

0

The stuff in .terraform/modules/ec2-datapipeline/main.tf is actually the main.tf file from an external module called "ec2-datapipeline" referenced somewhere in your own code (look for module "ec2-datapipeline").

You have to fix the bug in the source for "ec2-datapipeline", commit and tag it, then update the source reference in your own code.

The reason your changes disappear on reinitialization is, that you passed the --upgrade switch which tells Terraform to redownload the external module sources, even if they are cached locally in the .terraform/modules cache.

于 2021-09-26T09:49:53.353 回答