반응형
Terraform - 웹 서버에 연결할 수 없음 - 인스턴스가 서비스를 종료했습니다
웹 서버로 작동하기 위해 VPC 내에 ec2 인스턴스를 배포하기 위해 아래 테라폼 코드를 실행하고 있지만, 어떤 이유로 웹 사이트에 접속할 수 없고, 수신 및 송신 규칙을 올바르게 설정했습니다:
########Provider########
provider "aws" {
region = "us-west-2"
access_key = "[redacted]"
secret_key = "[redacted]"
}
########VPC########
resource "aws_vpc" "vpc1" {
cidr_block = "10.1.0.0/16"
tags = {
Name = "Production"
}
}
########Internet GW########
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc1.id
}
########Route table########
resource "aws_route_table" "rt" {
vpc_id = aws_vpc.vpc1.id
route {
cidr_block = "0.0.0.0/24"
gateway_id = aws_internet_gateway.gw.id
}
route {
ipv6_cidr_block = "::/0"
gateway_id = aws_internet_gateway.gw.id
}
}
########Sub Net########
resource "aws_subnet" "subnet1" {
vpc_id = aws_vpc.vpc1.id
cidr_block = "10.1.0.0/24"
availability_zone = "us-west-2a"
map_public_ip_on_launch = "true"
tags = {
Name = "prod-subnet-1"
}
}
########RT assosiation########
resource "aws_route_table_association" "a" {
subnet_id = aws_subnet.subnet1.id
route_table_id = aws_route_table.rt.id
}
########Security Group########
resource "aws_security_group" "sec1" {
name = "allow_web"
description = "Allow web inbound traffic"
vpc_id = aws_vpc.vpc1.id
ingress {
description = "HTTP from VPC"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["10.1.0.0/16"]
}
#SSH access from anywhere
ingress {
description = "SSH from VPC"
from_port = 22
to_port = 22
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 = {
Name = "allow_web"
}
}
########Net Interface for the Instance########
#resource "aws_network_interface" "wsn" {
# subnet_id = aws_subnet.subnet1.id
# private_ips = ["10.0.1.50"]
# security_groups = [aws_security_group.sec1.id]
#}
########Load Balancer########
resource "aws_elb" "elb" {
name = "lb"
subnets = [aws_subnet.subnet1.id]
security_groups = [aws_security_group.sec1.id]
instances = [aws_instance.web1.id]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
}
########EC2 Instance########
resource "aws_instance" "web1" {
ami = "ami-003634241a8fcdec0" #ubuntu 18.4
instance_type = "t2.micro"
availability_zone = "us-west-2a"
key_name = "main-key"
subnet_id = aws_subnet.subnet1.id
#network_interface {
# device_index = 0
# network_interface_id = aws_network_interface.wsn.id
#}
user_data = <<-EOF
#!/bin/bash
sudo apt update -y
sudo apt install apache2 -y
sudo systemctl start apache2
sudo bash -c 'echo Hello world!!! > /var/www/html/index.html'
EOF
tags = {
Name = "HelloWorld"
}
}
output "aws_elb_public_dns" {
value = aws_elb.elb.dns_name
}
계획 및 적용은 정상적으로 실행되지만 로드 밸런서의 인스턴스가 "Out of Service"인 경우 여기서 무엇이 잘못될 수 있습니까??
당신은 당신의 예에 있습니다: .
그 후에, 당신은 그것에 ssh할 수 없을 것이고 외부로부터 http 트래픽이 허용될 것이다.
너의 것도. 다음과 같아야 합니다:
cidr_block = "0.0.0.0/0"
인터넷에서 트래픽을 허용하는 ELB의 SG도 마찬가지입니다. 다음과 같아야 합니다:
cidr_blocks = ["0.0.0.0/0"]
반응형
'개발하자' 카테고리의 다른 글
Python: 이메일을 보낼 때 다른 우편함 사용 (0) | 2023.05.16 |
---|---|
PythonService를 사용합니다.가상 환경을 사용하는 동안 python 서비스를 호스팅하기 위해 exe (1) | 2023.05.16 |
벨벳 키트에서 마크다운 파일을 가져오는 방법은 무엇입니까? (0) | 2023.05.15 |
왜 쿠버네티스에 있는 포드들이 서비스 계정 비밀을 자동으로 탑재하고 있나요? (1) | 2023.05.14 |
kubernetes에서 네임스페이스를 전환하는 방법 (1) | 2023.05.13 |