gpt4 book ai didi

amazon-web-services - │ 错误 : Reference to undeclared resource

转载 作者:行者123 更新时间:2023-12-04 11:25:47 25 4
gpt4 key购买 nike

我是 terraform 的新手,并试图通过下图制作一个 AWS (t2.nano) 实例。
这是我的 tf 文件:

provider "aws" {
profile = "default"
region = "us-west-2"
}

resource "aws_s3_bucket" "prod_tf_course" {
bucket = "tf-course-20210607"
acl = "private"
}

resource "aws_default_vpc" "default" {}

resource "aws_security_group" "group_web"{
name = "prod_web"
description = "allow standard http and https ports inbound and everithing outbound"

ingress{
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress{
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]

}
tags = {
"Terraform" : "true"
}

}

resource "aws_instance" "prod_web"{
ami = "ami-05105e44227712eb6"
instance_type ="t2.nano"

vpc_security_group_ids = [
aws_security_group.prod_web.id
]

tags = {
"Terraform" : "true"
}
}
当我运行命令时 terraform plan ,其产生以下错误:
$ terraform plan

│ Error: Reference to undeclared resource

│ on prod.tf line 50, in resource "aws_instance" "prod_web":
│ 50: aws_security_group.prod_web.id

│ A managed resource "aws_security_group" "prod_web" has not been declared in
│ the root module.

如果有人能帮我解决它,我会很高兴。

最佳答案

它应该是:

  vpc_security_group_ids = [
aws_security_group.group_web.id
]
作为您的 aws_security_group被称为 group_web ,不是 prod_web .

关于amazon-web-services - │ 错误 : Reference to undeclared resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68334932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com