错误:收集实例设置时出错:运行 terraform apply 时结果为空(terraform plan 工作正常)

mbm*_*020 3 amazon-ec2 terraform terraform-provider-aws terraform0.12+

我不太明白 terraform 目录是如何设置的,但我的目录似乎非常基本。尽管设置了空值,但它一直抱怨空值。有人可以看一下并告诉我可能是什么问题吗?

\n

.tf 的片段:

\n
provider "aws" {\n  region     = var.region\n\n  default_tags {\n    tags = {\n      source = "/home/ubuntu/bootcamp-terraform-master"\n      owner_name = var.owner-name\n      owner_email = var.owner-email\n      purpose = var.purpose\n    }\n  }\n}\n\n\n// Resources\n\nresource "aws_instance" "zookeepers" {\n  count         = var.zk-count\n  ami           = var.aws-ami-id\n  instance_type = var.zk-instance-type\n  key_name = var.key-name\n\n  root_block_device {\n    volume_size = 100\n  }\n\n  tags = {\n    Name = "${var.owner-name}-zookeeper-${count.index}"\n"bootcamp2.tf" 269L, 7806C                                                                                                                              14,0-1        Top\nprovider "aws" {\n  region     = var.region\n\n  default_tags {\n    tags = {\n      source = "/home/ubuntu/bootcamp-terraform-master"\n      owner_name = var.owner-name\n      owner_email = var.owner-email\n      purpose = var.purpose\n    }\n  }\n}\n\n\n// Resources\n\nresource "aws_instance" "zookeepers" {\n  count         = var.zk-count\n  ami           = var.aws-ami-id\n  instance_type = var.zk-instance-type\n  key_name = var.key-name\n\n  root_block_device {\n    volume_size = 100\n  }\n\n  tags = {\n    Name = "${var.owner-name}-zookeeper-${count.index}"\n    description = "zookeeper nodes - Managed by Terraform"\n    role = "zookeeper"\n    zookeeperid = count.index\n    Schedule = "zookeeper-mon-8am-fri-6pm"\n    sshUser = var.linux-user\n    region = var.region\n    role_region = "zookeepers-${var.region}"\n  }\n\n  subnet_id = var.subnet-id[count.index % length(var.subnet-id)]\n  availability_zone = var.availability-zone[count.index % length(var.availability-zone)]\n  vpc_security_group_ids = var.vpc-security-group-ids\n  associate_public_ip_address = true\n}\n\nresource "aws_route53_record" "zookeepers" {\n  count = var.zk-count\n  zone_id = var.hosted-zone-id\n  name = "zookeeper-${count.index}.${var.dns-suffix}"\n  type = "A"\n  ttl = "300"\n  records = ["${element(aws_instance.zookeepers.*.private_ip, count.index)}"]\n}\n\nresource "aws_instance" "brokers" {\n  count         = var.broker-count\n  ami           = var.aws-ami-id\n  instance_type = var.broker-instance-type\n  availability_zone = var.availability-zone[count.index % length(var.availability-zone)]\n\n    # security_groups = ["${var.security_group}"]\n  key_name = var.key-name\n\n  root_block_device {\n    volume_size = 64 # 64 GB\n  }\n\n  tags = {\n    Name = "${var.owner-name}-broker-${count.index}"\n    description = "broker nodes - Managed by Terraform"\n    nice-name = "kafka-${count.index}"\n    big-nice-name = "follower-kafka-${count.index}"\n    brokerid = count.index\n    role = "broker"\n    sshUser = var.linux-user\n    # sshPrivateIp = true // this is only checked for existence, not if it's true or false by terraform.py (ati)\n    createdBy = "terraform"\n    Schedule = "kafka-mon-8am-fri-6pm"\n    # ansible_python_interpreter = "/usr/bin/python3"\n    #EntScheduler = "mon,tue,wed,thu,fri;1600;mon,tue,wed,thu;fri;sat;0400;"\n    region = var.region\n    role_region = "brokers-${var.region}"\n  }\n\n  subnet_id = var.subnet-id[count.index % length(var.subnet-id)]\n  vpc_security_group_ids = var.vpc-security-group-ids\n  associate_public_ip_address = true\n}\n\nresource "aws_route53_record" "brokers" {\n  count = var.broker-count\n  zone_id = var.hosted-zone-id\n  name = "kafka-${count.index}.${var.dns-suffix}"\n  type = "A"\n  ttl = "300"\n  records = ["${element(aws_instance.brokers.*.private_ip, count.index)}"]\n}\n\nresource "aws_instance" "connect-cluster" {\n  count         = var.connect-count\n  ami           = var.aws-ami-id\n  instance_type = var.connect-instance-type\n  availability_zone = var.availability-zone[count.index % length(var.availability-zone)]\n  key_name = var.key-name\n  tags = {\n    Name = "${var.owner-name}-connect-${count.index}"\n    description = "Connect nodes - Managed by Terraform"\n    role = "connect"\n    Schedule = "mon-8am-fri-6pm"\n    sshUser = var.linux-user\n    region = var.region\n    role_region = "connect-${var.region}"\n  }\n\n  root_block_device {\n    volume_size = 20 # 20 GB\n  }\n\n  subnet_id = var.subnet-id[count.index % length(var.subnet-id)]\n  vpc_security_group_ids = var.vpc-security-group-ids\n  associate_public_ip_address = true\n}\n\nresource "aws_route53_record" "connect-cluster" {\n  count = var.connect-count\n  zone_id = var.hosted-zone-id\n  name = "connect-${count.index}.${var.dns-suffix}"\n  type = "A"\n  ttl = "300"\n  records = ["${element(aws_instance.connect-cluster.*.private_ip, count.index)}"]\n}\n\nresource "aws_instance" "schema" {\n  count         = var.schema-count\n  ami           = var.aws-ami-id\n  instance_type = var.schema-instance-type\n  availability_zone = var.availability-zone[count.index % length(var.availability-zone)]\n  key_name = var.key-name\n  tags = {\n    Name = "${var.owner-name}-schema-${count.index}"\n    description = "Schema nodes - Managed by Terraform"\n    role = "schema"\n    Schedule = "mon-8am-fri-6pm"\n    sshUser = var.linux-user\n    region = var.region\n    role_region = "schema-${var.region}"\n  }\n\n  root_block_device {\n    volume_size = 20 # 20 GB\n }\n\n  subnet_id = var.subnet-id[count.index % length(var.subnet-id)]\n  vpc_security_group_ids = var.vpc-security-group-ids\n  associate_public_ip_address = true\n}\n\nresource "aws_route53_record" "schema" {\n  count = var.schema-count\n  zone_id = var.hosted-zone-id\n  name = "schema-${count.index}.${var.dns-suffix}"\n  type = "A"\n  ttl = "300"\n  records = ["${element(aws_instance.schema.*.private_ip, count.index)}"]\n}\n\nresource "aws_instance" "control-center" {\n  count         = var.c3-count\n  ami           = var.aws-ami-id\n  instance_type = var.c3-instance-type\n  availability_zone = var.availability-zone[count.index % length(var.availability-zone)]\n  key_name = var.key-name\n\n  root_block_device {\n    volume_size = 64 # 64GB\n  }\n\n  tags = {\n    Name = "${var.owner-name}-control-center-${count.index}"\n    description = "Control Center nodes - Managed by Terraform"\n    role = "schema"\n    Schedule = "mon-8am-fri-6pm"\n    sshUser = var.linux-user\n    region = var.region\n    role_region = "schema-${var.region}"\n  }\n\n  subnet_id = var.subnet-id[count.index % length(var.subnet-id)]\n  vpc_security_group_ids = var.vpc-security-group-ids\n  associate_public_ip_address = true\n}\n\nresource "aws_route53_record" "control-center" {\n  count = var.c3-count\n  zone_id = var.hosted-zone-id\n  name = "controlcenter-${count.index}.${var.dns-suffix}"\n  type = "A"\n  ttl = "300"\n  records = ["${element(aws_instance.control-center.*.private_ip, count.index)}"]\n}\n\nresource "aws_instance" "rest" {\n  count         = var.rest-count\n  ami           = var.aws-ami-id\n  instance_type = var.rest-instance-type\n  availability_zone = var.availability-zone[count.index % length(var.availability-zone)]\n\n  key_name = var.key-name\n\n  root_block_device {\n    volume_size = 20 # 20 GB\n  }\n\n  tags = {\n    Name = "${var.owner-name}-rest-${count.index}"\n    description = "Rest nodes - Managed by Terraform"\n    role = "schema"\n    Schedule = "mon-8am-fri-6pm"\n    sshUser = var.linux-user\n    region = var.region\n    role_region = "schema-${var.region}"\n  }\n\n  subnet_id = var.subnet-id[count.index % length(var.subnet-id)]\n  vpc_security_group_ids = var.vpc-security-group-ids\n  associate_public_ip_address = true\n}\n\nresource "aws_route53_record" "rest" {\n  count = var.rest-count\n  zone_id = var.hosted-zone-id\n  name = "rest-${count.index}.${var.dns-suffix}"\n  type = "A"\n  ttl = "300"\n  records = ["${element(aws_instance.rest.*.private_ip, count.index)}"]\n}\n\nresource "aws_instance" "ksql" {\n  count         = var.ksql-count\n  ami           = var.aws-ami-id\n  instance_type = var.ksql-instance-type\n  availability_zone = var.availability-zone[count.index % length(var.availability-zone)]\n  key_name = var.key-name\n\n  root_block_device {\n    volume_size = 64 # 64 GB\n  }\n\n  tags = {\n    Name = "${var.owner-name}-ksql-${count.index}"\n    description = "Rest nodes - Managed by Terraform"\n    role = "schema"\n    Schedule = "mon-8am-fri-6pm"\n    sshUser = var.linux-user\n    region = var.region\n    role_region = "schema-${var.region}"\n  }\n\n  subnet_id = var.subnet-id[count.index % length(var.subnet-id)]\n  vpc_security_group_ids = var.vpc-security-group-ids\n  associate_public_ip_address = true\n}\n\nresource "aws_route53_record" "ksql" {\n  count = var.ksql-count\n  zone_id = var.hosted-zone-id\n  name = "ksql-${count.index}.${var.dns-suffix}"\n  type = "A"\n  ttl = "300"\n  records = ["${element(aws_instance.ksql.*.private_ip, count.index)}"]\n}\n
Run Code Online (Sandbox Code Playgroud)\n

terraform plan 运行良好,但在运行 terraform apply 时我不断遇到这些错误

\n
Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.zookeepers[1],\n\xe2\x94\x82   on bootcamp2.tf line 17, in resource "aws_instance" "zookeepers":\n\xe2\x94\x82   17: resource "aws_instance" "zookeepers" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.zookeepers[0],\n\xe2\x94\x82   on bootcamp2.tf line 17, in resource "aws_instance" "zookeepers":\n\xe2\x94\x82   17: resource "aws_instance" "zookeepers" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.zookeepers[2],\n\xe2\x94\x82   on bootcamp2.tf line 17, in resource "aws_instance" "zookeepers":\n\xe2\x94\x82   17: resource "aws_instance" "zookeepers" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.brokers[0],\n\xe2\x94\x82   on bootcamp2.tf line 53, in resource "aws_instance" "brokers":\n\xe2\x94\x82   53: resource "aws_instance" "brokers" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.brokers[1],\n\xe2\x94\x82   on bootcamp2.tf line 53, in resource "aws_instance" "brokers":\n\xe2\x94\x82   53: resource "aws_instance" "brokers" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.brokers[2],\n\xe2\x94\x82   on bootcamp2.tf line 53, in resource "aws_instance" "brokers":\n\xe2\x94\x82   53: resource "aws_instance" "brokers" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.connect-cluster[0],\n\xe2\x94\x82   on bootcamp2.tf line 97, in resource "aws_instance" "connect-cluster":\n\xe2\x94\x82   97: resource "aws_instance" "connect-cluster" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.connect-cluster[1],\n\xe2\x94\x82   on bootcamp2.tf line 97, in resource "aws_instance" "connect-cluster":\n\xe2\x94\x82   97: resource "aws_instance" "connect-cluster" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.schema[0],\n\xe2\x94\x82   on bootcamp2.tf line 131, in resource "aws_instance" "schema":\n\xe2\x94\x82  131: resource "aws_instance" "schema" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.schema[1],\n\xe2\x94\x82   on bootcamp2.tf line 131, in resource "aws_instance" "schema":\n\xe2\x94\x82  131: resource "aws_instance" "schema" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.control-center[0],\n\xe2\x94\x82   on bootcamp2.tf line 165, in resource "aws_instance" "control-center":\n\xe2\x94\x82  165: resource "aws_instance" "control-center" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.rest[0],\n\xe2\x94\x82   on bootcamp2.tf line 200, in resource "aws_instance" "rest":\n\xe2\x94\x82  200: resource "aws_instance" "rest" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.ksql[0],\n\xe2\x94\x82   on bootcamp2.tf line 236, in resource "aws_instance" "ksql":\n\xe2\x94\x82  236: resource "aws_instance" "ksql" {\n\xe2\x94\x82\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error collecting instance settings: empty result\n\xe2\x94\x82\n\xe2\x94\x82   with aws_instance.ksql[1],\n\xe2\x94\x82   on bootcamp2.tf line 236, in resource "aws_instance" "ksql":\n\xe2\x94\x82  236: resource "aws_instance" "ksql" {\n
Run Code Online (Sandbox Code Playgroud)\n

所有变量都在 Variables.tf 文件中设置,并引用 .tfvars 文件:

\n
variable "owner-name" {\n  default = "wetfwefwef"\n}\n\nvariable "owner-email" {\n  default = "stwfefxef.io"\n}\n\nvariable "dns-suffix" {\n  default = "srgrwgsofxfwegwegia"\n  description = "Suffix for DNS entry in Route 53. No spaces!"\n}\n\nvariable "purpose" {\n  default = "rhwgrwx"\n}\n\nvariable "key-name" {\n  default = "tertqwf"\n}\n\nvariable "zk-count" {\n  default = 3\n}\n\nvariable "broker-count" {\n  default = 3\n}\n\nvariable "connect-count" {\n  default = 2\n}\n\nvariable "schema-count" {\n  default = 2\n}\n\nvariable "rest-count" {\n  default = 1\n}\n\nvariable "c3-count" {\n  default = 1\n}\n\nvariable "ksql-count" {\n  default = 2\n}\n\nvariable "zk-instance-type" {\n  default = "t3a.large"\n}\n\nvariable "broker-instance-type" {\n  default = "t3a.large"\n}\n\nvariable "schema-instance-type" {\n  default = "t3a.large"\n}\n\nvariable "connect-instance-type" {\n  default = "t3a.large"\n}\n\nvariable "rest-instance-type" {\n  default = "t3a.large"\n}\n\nvariable "c3-instance-type" {\n  default = "t3a.large"\n}\n\nvariable "ksql-instance-type" {\n  default = "t3a.large"\n}\n\nvariable "client-instance-type" {\n  default = "t3a.large"\n}\n\nvariable "hosted-zone-id" {\n}\n\n\nvariable "aws-ami-id"  {\n  default = "ami-00000000"\n}\n\nvariable "linux-user" {\n  default = "ubuntu" // ec2-user\n}\n\nvariable "vpc-id" {\n}\n\nvariable "subnet-id" {\n  type = list(string)\n}\n\nvariable "vpc-security-group-ids" {\n  type = list(string)\n}\n
Run Code Online (Sandbox Code Playgroud)\n

lam*_*ier 10

我偶然发现了这个问题,试图快速找到为什么我会遇到同样错误的答案。

我很确定这是因为您提供的默认 AMI 不存在。否则,认为您可能提供了错误的值作为变量,或者 AMI 未与您运行它的帐户共享。就我而言,这是最后一个问题:在控制台中,我已将帐户添加到在 AMI 中共享,但未进行保存:-/

Error: error collecting instance settings: empty result

对于诊断问题来说不是很具有描述性。我猜可能是其他一些领域没有给出结果——没有进一步观察。如果这是评论之一中建议的密钥对问题,您会在错误消息中清楚地看到,包括InvalidKeyPair.NotFound.

要进一步调试,您可以增加日志记录,例如export TF_LOG=debug