- 19, Oct 2024
- #1
Как указано в заголовке вопроса, у меня есть файл Terraform (прикреплен ниже), но создаваемая им инфраструктура не позволяет мне подключаться по SSH (я получаю сообщение «Время ожидания соединения истекло»). Таким образом, либо пакеты не доходят до экземпляров EC2, либо ответы не доходят. Есть идеи? Для целей этого вопроса DNS и ALB можно игнорировать (первый работает нормально, второй почти наверняка еще нет).
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
}
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.vpc.id}"
}
resource "aws_subnet" "subnet_a" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "10.0.1.0/24"
availability_zone = "us-west-2a"
}
resource "aws_subnet" "subnet_b" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "10.0.2.0/24"
availability_zone = "us-west-2b"
}
resource "aws_route_table" "rt" {
vpc_id = "${aws_vpc.vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}
}
resource "aws_route_table_association" "rt_a" {
subnet_id = "${aws_subnet.subnet_a.id}"
route_table_id = "${aws_route_table.rt.id}"
}
resource "aws_route_table_association" "rt_b" {
subnet_id = "${aws_subnet.subnet_b.id}"
route_table_id = "${aws_route_table.rt.id}"
}
resource "aws_security_group" "alb_sg" {
vpc_id = "${aws_vpc.vpc.id}"
ingress {
from_port = 0
to_port = 80
protocol = "tcp"
}
ingress {
from_port = 0
to_port = 443
protocol = "tcp"
}
}
resource "aws_alb" "alb" {
internal = false
load_balancer_type = "application"
security_groups = ["${aws_security_group.alb_sg.id}"]
subnets = ["${aws_subnet.subnet_a.id}","${aws_subnet.subnet_b.id}"]
}
resource "aws_route53_zone" "primary" {
name = "REDACTED.REDACTED"
}
resource "aws_route53_record" "alias_route53_record" {
zone_id = "${aws_route53_zone.primary.zone_id}"
name = "REDACTED.REDACTED"
type = "A"
alias {
name = "${aws_alb.alb.dns_name}"
zone_id = "${aws_alb.alb.zone_id}"
evaluate_target_health = true
}
}
resource "aws_key_pair" "kp" {
key_name = "kp2019y09m25d001i"
public_key = "ssh-rsa REDACTED"
}
resource "aws_instance" "instance_a" {
ami = "ami-08ba47c10a42c61be"
instance_type = "t2.micro"
availability_zone = "us-west-2a"
subnet_id = "${aws_subnet.subnet_a.id}"
associate_public_ip_address = true
key_name = "${aws_key_pair.kp.key_name}"
}
resource "aws_instance" "instance_b" {
ami = "ami-08ba47c10a42c61be"
instance_type = "t2.micro"
availability_zone = "us-west-2b"
subnet_id = "${aws_subnet.subnet_b.id}"
associate_public_ip_address = true
key_name = "${aws_key_pair.kp.key_name}"
}
output "instance_a_ip" {
value = "${aws_instance.instance_a.public_ip}"
}
output "instance_b_ip" {
value = "${aws_instance.instance_b.public_ip}"
}
#amazon-ec2 #terraform #aws-vpc