【发布时间】:2021-06-18 03:22:41
【问题描述】:
我正在设置我的第一个 terraform 目标组,目前卡在中间。
这是我的资源代码
resource "aws_lb_target_group" "ami_tg" {
name = "ami-lb-tg-${substr(uuid(), 0, 3)}"
port = var.tg_port
protocol = var.tg_protocol
vpc_id = var.vpc_id
health_check {
healthy_threshold = var.elb_healthy_threshold
unhealthy_threshold = var.elb_unhealthy_threshold
timeout = var.elb_timeout
interval = var.elb_interval
}
}
显然我传递给了我的 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.
这里的任何建议将不胜感激
【问题讨论】:
-
module.networking.vpc_id到底是什么?您的module.networking中是如何定义的? -
这意味着我在网络目录中定义的 vpc 资源代码因此传递到 tg 目录,因为我创建了一个新目录,在这种情况下是 alb #-----network/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}
-
但是
outputvpc_id 是如何定义的呢? -
#---networking/outputs.tf 输出 "vpc_id" { value = aws_vpc.HH_vpc }
标签: amazon-web-services terraform