Amazon web services 属性“”的值不正确;vpc_id";:需要字符串 我正在设置我的第一个TrrFrac目标组,目前卡在中间。

Amazon web services 属性“”的值不正确;vpc_id";:需要字符串 我正在设置我的第一个TrrFrac目标组,目前卡在中间。,amazon-web-services,terraform,Amazon Web Services,Terraform,这是我的资源代码 很明显,我已经转到了variable.tf文件 variable "tg_port" {} variable "tg_protocol" {} variable "elb_healthy_threshold" {} variable "elb_unhealthy_threshold" {} variable "elb_timeout" {} variable "elb_

这是我的资源代码

很明显,我已经转到了variable.tf文件

variable "tg_port" {}
variable "tg_protocol" {}
variable "elb_healthy_threshold" {}
variable "elb_unhealthy_threshold" {}
variable "elb_timeout" {}
variable "elb_interval" {}
variable "vpc_id" {}
然后添加到我的root/main.tf模块文件中

   module "alb" {
  source                  = "./alb"
  tg_port                 = 80
  tg_protocol             = "HTTP"
  vpc_id                  = module.networking.vpc_id
  elb_healthy_threshold   = 2
  elb_unhealthy_threshold = 2
  elb_timeout             = 3
  elb_interval            = 30
}
但每当我运行terraform plan时,我总是得到以下错误

Error: Incorrect attribute value type

  on alb/main.tf line 16, in resource "aws_lb_target_group" "ami_tg":
  16:   vpc_id   = var.vpc_id
    |----------------
    | var.vpc_id is object with 19 attributes

Inappropriate value for attribute "vpc_id": string required.
如有任何建议,我们将不胜感激

您的输出:

output "vpc_id" { 
    value = aws_vpc.HH_vpc
}
返回整个
HH\u vpc
对象,而不仅仅是它的id。要只返回id,它应该是:

output "vpc_id" { 
    value = aws_vpc.HH_vpc.id
}
您的输出:

output "vpc_id" { 
    value = aws_vpc.HH_vpc
}
返回整个
HH\u vpc
对象,而不仅仅是它的id。要只返回id,它应该是:

output "vpc_id" { 
    value = aws_vpc.HH_vpc.id
}

什么是
module.networking.vpc\u id
?在您的
模块.networking
中是如何定义的?这意味着我的vpc资源代码在networking目录中定义,从而传递到tg目录,因为我创建了一个新目录,在本例中是alb----networking/main.tf。。。资源“aws_vpc”“HH_vpc”{cidr_block=var.vpc_cidr enable_dns_hostnames=true enable_dns_support=true tags={Name=“HH vpc${random_integer.random.id}但
输出
vpc_id是如何定义的?#--networking/outputs.tf output“vpc_id”{value=aws\vpc.hu vpc}什么是
module.networking.vpc_id
?它在您的
module.networking
中是如何定义的?这意味着我的vpc资源代码在networking目录中定义,从而传递到tg目录,因为我创建了一个新目录,在本例中是alb----networking/main.tf…resource“aws#vpc”HH_vpc“{cidr_block=var.vpc_cidr enable_dns_hostnames=true enable_dns_support=true tags={Name=“HH vpc${random_integer.random.id}但是
输出
vpc\u id是如何定义的呢?#--networking/outputs.tf output“vpc\u id”{value=aws\u vpc.HH\vpc}这就是我无法理解的——谢谢你的帮助help@Hamdi没问题。如果答案有帮助,我们将非常感谢您的接受。有一个技巧可以帮助您更准确地发现此类错误,那就是确保始终声明每个变量的预期类型。对于这个特定变量,您可以通过编写
type=string
变量“vpc\u id”块中。在这种情况下,Terraform会在
模块“alb”中报告问题
block,这仍然不是直接原因,但至少减少了调试时需要检查的配置部分。这是我无法理解的-感谢您的帮助help@Hamdi没问题。如果答案是有帮助的,我们将不胜感激。这是一个可以帮助我们更准确地发现此类错误的提示用法是确保始终声明每个变量的预期类型。对于此特定变量,您可以通过在
变量“vpc_id”
块中写入
type=string
来实现。在这种情况下,Terraform会在
模块“alb”中报告问题
block,这仍然不是直接原因,但至少减少了调试时需要查看的配置部分。