Tentei pelo NAT gateway conforme o curso, porém sem sucesso. Verifiquei que atualmente a AWS está utilizando o VPC endpoint com ECR. Modifiquei os códigos e ainda não está conseguindo obter a imagem.
Task stopped at: 2024-02-24T10:15:59.264Z CannotPullContainerError: ref pull has been retried 5 time(s): failed to copy: httpReadSeeker: failed open: failed to do request: Get xxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/production:V1: dial tcp 52.92.163.10:443: i/o timeout
VPC.tf:
module "vpc" {
.......
}
# Create a VPC endpoint for ECR in the private subnet
resource "aws_vpc_endpoint" "ecr_dkr_endpoint" {
depends_on = [aws_ecr_repository.ecr_repository]
service_name = "com.amazonaws.${var.aws_region}.ecr.dkr"
vpc_id = module.vpc.vpc_id
vpc_endpoint_type = "Interface"
private_dns_enabled = true
subnet_ids = module.vpc.private_subnets
security_group_ids = [aws_security_group.vpc_endpoint_service.id, aws_security_group.privatenet.id]
}
resource "aws_vpc_endpoint" "ecr_api_endpoint" {
depends_on = [aws_ecr_repository.ecr_repository]
service_name = "com.amazonaws.${var.aws_region}.ecr.api"
vpc_id = module.vpc.vpc_id
vpc_endpoint_type = "Interface"
private_dns_enabled = true
subnet_ids = module.vpc.private_subnets
security_group_ids = [aws_security_group.vpc_endpoint_service.id, aws_security_group.privatenet.id]
}
resource "aws_vpc_endpoint" "s3" {
depends_on = [aws_ecr_repository.ecr_repository]
vpc_id = module.vpc.vpc_id
service_name = "com.amazonaws.${var.aws_region}.s3"
}
Estou com a impressão de que é alguma falha nos grupos de segurança.
# Public Subnet security group (ALB)
resource "aws_security_group" "alb" {
name = "alb_ECS"
description = "Application Load Balancer - Public"
vpc_id = module.vpc.vpc_id
}
resource "aws_security_group_rule" "ingress_alb" {
type = "ingress"
from_port = 8000 # Ports allowed to access the ALB
to_port = 8000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # 0.0.0.0 - 255.255.255.255
# ipv6_cidr_blocks = [aws_vpc.example.ipv6_cidr_block]
security_group_id = aws_security_group.alb.id # The ID of the security group to authorize access to.
}
resource "aws_security_group_rule" "egress_alb" {
type = "egress"
from_port = 0 # Ports allowed to respond
to_port = 0
protocol = "-1" # All protocols
cidr_blocks = ["0.0.0.0/0"] # 0.0.0.0 - 255.255.255.255
# ipv6_cidr_blocks = [aws_vpc.example.ipv6_cidr_block]
security_group_id = aws_security_group.alb.id # The ID of the security group to authorize access to.
}
# Private Subnet security group
resource "aws_security_group" "privatenet" {
name = "private_ECS"
description = "To access the Private subnet"
vpc_id = module.vpc.vpc_id
# tags = {
# Name = "alb"
# }
}
resource "aws_security_group_rule" "ingress_ECS" {
type = "ingress"
from_port = 0 # Ports allowed to access the Private subnet
to_port = 0
protocol = "-1"
source_security_group_id = aws_security_group.alb.id # Ingress only from the ALB Security Group
security_group_id = aws_security_group.privatenet.id # The ID of the security group to authorize access to.
}
resource "aws_security_group_rule" "egress_ECS" {
type = "egress"
from_port = 0 # Ports allowed to respond
to_port = 0
protocol = "-1" # All protocols
source_security_group_id = aws_security_group.alb.id # Egress only to the ALB Security Group
# ipv6_cidr_blocks = [aws_vpc.example.ipv6_cidr_block]
security_group_id = aws_security_group.privatenet.id # The ID of the security group to authorize access to.
}
# Private VPC endpoint security group
resource "aws_security_group" "vpc_endpoint_service" {
name = "private_VPC_endpoint"
description = "To access the Private subnet"
vpc_id = module.vpc.vpc_id
}
# Allow traffic to and from the ECR endpoint
resource "aws_security_group_rule" "ingress_ECR" {
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
# self = true
# cidr_blocks = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
cidr_blocks = ["0.0.0.0/0"]
# prefix_list_ids = [data.aws_prefix_list.ecr_api_endpoint.id, data.aws_prefix_list.ecr_dkr_endpoint.id]
security_group_id = aws_security_group.vpc_endpoint_service.id
}
resource "aws_security_group_rule" "egress_ECR" {
type = "egress"
from_port = 443
to_port = 443
protocol = "tcp"
# self = true # not necessary if cidr_blocks = ["0.0.0.0/0"]
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.vpc_endpoint_service.id
}