Orl*_*rly 5 amazon-ec2 amazon-web-services terraform terraform-provider-aws
我是 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"
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行命令时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.
?
Run Code Online (Sandbox Code Playgroud)
如果有人能帮我解决它,我会很高兴。
它应该是:
vpc_security_group_ids = [
aws_security_group.group_web.id
]
Run Code Online (Sandbox Code Playgroud)
正如你aws_security_group所称的group_web,不是prod_web。
| 归档时间: |
|
| 查看次数: |
68 次 |
| 最近记录: |