我正在尝试使用Terraform创建EC2实例并设置负载均衡器,但我遇到了以下错误。如何在单个main.tf文件中创建实例和配置负载均衡器?
错误:引用未声明的资源
"aws_lb_target_group" "front-end":27: vpc_id = "${aws_vpc.terrafom-elb.id}" 在根模块中未声明托管资源 "aws_vpc" "terrafom-elb"。
代码:
region = "us-east-1"
access_key = "*********************"
secret_key = "**********************"
}
resource "aws_instance" "terraform" {
ami = "ami-07ebfd5b3428b6f4d"
instance_type = "t2.micro"
security_groups = ["nodejs","default"]
tags = {
Name = "terrafom-elb"
}
}
resource "aws_lb" "front-end"{
name = "front-end-lb"
internal = false
security_groups = ["nodejs"]
}
resource "aws_lb_target_group" "front-end" {
name = "front-end"
port = 8989
protocol = "HTTP"
vpc_id = "${aws_vpc.terrafom-elb.id}"
depends_on = [aws_instance.terraform]
}
aws_vpc
资源。你可以分享包含该资源的其他配置吗? - Matt Schuchard