AWS web服务器拒绝连接


provider "aws" {
region = "us-east-1"
}
provider "random" {}
resource "random_pet" "name" {}
resource "aws_instance" "web" {
ami           = "ami-0022f774911c1d690"
instance_type = "t2.micro"
user_data     = file("init-script.sh")
vpc_security_group_ids = [aws_security_group.web-sg.id]
tags = {
Name = random_pet.name.id
}
}
resource "aws_security_group" "web-sg" {
name = "${random_pet.name.id}-sg"
ingress {
from_port = 80
to_port = 80
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"]
}
}

我正在使用Terraform部署一个PHP web服务器。如图所示,定义了入口出口规则,我应该能够连接。我做错了什么?

同样,我遵循这个教程:

https://learn.hashicorp.com/tutorials/terraform/resource?in=terraform/configuration-language

我自己克隆并运行了这个教程&这对我也不管用。尝试连接时出现超时错误。

1日观察-它很老了& &;这不是一个很好的教程。它所采样的AMI甚至已经不存在了&我使用了最新的AMZN Default Linux 2 AMI。

2日观察-在教程中没有创建或使用此EC2实例的密钥对,这使得故障排除变得困难,因为您无法连接&查看日志。

观察3-与我的第一个相关联,chkconfig用于初始化脚本&如果您使用的是较新的AMI (centos, redhat或amzn linux映像),它们都可能使用systemctl代替。

结论:这个教程真的需要更新了。我不建议使用它,因为它实际上是不可用的,而且非常过时。