resource "aws_route_table" "rt-datasaker-dev" {
  tags = {
    "Name" = "rt-datasaker-dev"
  }
  vpc_id = aws_vpc.vpc-datasaker.id
}


resource "aws_route" "route-private-rt-datasaker-dev-0-0-0-0--0" {
  destination_cidr_block = "0.0.0.0/0"
  nat_gateway_id         = aws_nat_gateway.natgw-datasaker.id
  route_table_id         = aws_route_table.rt-datasaker-dev.id
}



resource "aws_subnet" "sbn-dev-a" {
  availability_zone                           = "ap-northeast-2a"
  cidr_block                                  = "172.21.8.0/23"
  enable_resource_name_dns_a_record_on_launch = true
  private_dns_hostname_type_on_launch         = "resource-name"
  tags = {
    "Name"                                                  = "sbn-dev-a.datasaker"
    "SubnetType"                                            = "Private"
    "kubernetes.io/cluster/datasaker" = "owned"
    "kubernetes.io/cluster/dev.datasaker.io" = "shared"
    "kubernetes.io/role/elb"                                = "1"
    "kubernetes.io/role/internal-elb"                       = "1"
  }
  vpc_id = aws_vpc.vpc-datasaker.id
}

resource "aws_subnet" "sbn-dev-b" {
  availability_zone                           = "ap-northeast-2b"
  cidr_block                                  = "172.21.10.0/23"
  enable_resource_name_dns_a_record_on_launch = true
  private_dns_hostname_type_on_launch         = "resource-name"
  tags = {
    "Name"                                                  = "sbn-dev-b.datasaker"
    "SubnetType"                                            = "Private"
    "kubernetes.io/cluster/datasaker" = "owned"
    "kubernetes.io/cluster/dev.datasaker.io" = "shared"
    "kubernetes.io/role/elb"                                = "1"
    "kubernetes.io/role/internal-elb"                       = "1"
  }
  vpc_id = aws_vpc.vpc-datasaker.id
}

resource "aws_subnet" "sbn-dev-c" {
  availability_zone                           = "ap-northeast-2c"
  cidr_block                                  = "172.21.12.0/23"
  enable_resource_name_dns_a_record_on_launch = true
  private_dns_hostname_type_on_launch         = "resource-name"
  tags = {
    "Name"                                                  = "sbn-dev-c.datasaker"
    "SubnetType"                                            = "Private"
    "kubernetes.io/cluster/datasaker" = "owned"
    "kubernetes.io/cluster/dev.datasaker.io" = "shared"
    "kubernetes.io/role/elb"                                = "1"
    "kubernetes.io/role/internal-elb"                       = "1"
  }
  vpc_id = aws_vpc.vpc-datasaker.id
}


resource "aws_route_table_association" "rta-dev-a" {
  route_table_id = aws_route_table.rt-datasaker-dev.id
  subnet_id      = aws_subnet.sbn-dev-a.id
}

resource "aws_route_table_association" "rta-dev-b" {
  route_table_id = aws_route_table.rt-datasaker-dev.id
  subnet_id      = aws_subnet.sbn-dev-b.id
}

resource "aws_route_table_association" "rta-dev-c" {
  route_table_id = aws_route_table.rt-datasaker-dev.id
  subnet_id      = aws_subnet.sbn-dev-c.id
}

resource "aws_security_group" "sg-dev-datasaker" {
  description = "Security group dev-datasaker"
  name        = "secg-dev-datasaker"
  tags = {
    "Name" = "sg-dev-datasaker"
  }
  vpc_id = aws_vpc.vpc-datasaker.id
}


resource "aws_security_group_rule" "sgr-from-0-0-0-0--0-ingress-tcp-22to22-dev-datasaker-io" {
  cidr_blocks       = ["0.0.0.0/0"]
  from_port         = 22
  protocol          = "tcp"
  security_group_id = aws_security_group.sg-dev-datasaker.id
  to_port           = 22
  type              = "ingress"
}

resource "aws_security_group_rule" "sgr-from-0-0-0-0--0-ingress-icmp-dev-datasaker-io" {
  cidr_blocks       = ["0.0.0.0/0"]
  from_port         = 8
  protocol          = "icmp"
  security_group_id = aws_security_group.sg-dev-datasaker.id
  to_port           = 8
  type              = "ingress"
}

resource "aws_security_group_rule" "sgr-to-0-0-0-0--0-egress-icmp-dev-datasaker-io" {
  cidr_blocks       = ["0.0.0.0/0"]
  from_port         = 8
  protocol          = "icmp"
  security_group_id = aws_security_group.sg-dev-datasaker.id
  to_port           = 8
  type              = "egress"
}

resource "aws_security_group_rule" "sgr-from-0-0-0-0--0-engress-tcp-all-dev-datasaker-io" {
  cidr_blocks       = ["0.0.0.0/0"]
  from_port         = 0
  protocol          = "tcp"
  security_group_id = aws_security_group.sg-dev-datasaker.id
  to_port           = 65535
  type              = "egress"
}








