그냥 손으로 직접 AWS module들을 tf파일로 만들어 적는 것은 k8s 세팅을 하나하나 손으로 yaml파일 작성해서 적용하는 것 만큼이나 힘들다는 것을 깨달았다.
특히 k8s/eks 설정을 하다보니 문제가 엄청나게 발생했다.(tag, vpc, role 등)
https://github.com/terraform-aws-modules
위에서 module들을 import?해 사용하면 매우 편하게 사용할 수 있다.
다만 버전관리, property/method파악은 잘해야 한다.
해당 모듈을 이용해 다시 VPC 세팅을 해보았다.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "4.0.2"
name = "${var.cluster_name}-vpc"
cidr = var.cidr
azs = var.azs
private_subnets = var.private_subnets
public_subnets = var.public_subnets
intra_subnets = var.intra_subnets
enable_nat_gateway = true
enable_vpn_gateway = true
tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
}
public_subnet_tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"kubernetes.io/role/elb" = "1"
}
private_subnet_tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"kubernetes.io/role/internal-elb" = "1"
}
}
Again,
cidr : CIDR(Classless Inter-Domain Routing) block of vpc.The range of IP address.
azs : availability zone list.
intra_subnets :If you need private subnets that should have no Internet routing, intra_subnets should be specified. - good for control plane? -> provide isolation and help protect the control plane components from unauthorized access.
enable_nat_gateway = true ,enable_vpn_gateway = true
1. provision NAT gateway in the VPC, which will enable outbount internet connectivity for resources in private subnets.
2.provision a VPN gateway in the VPC, allowing for secure connectivity between the VPC and external networks.
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
This is for eks/k8s. This means that this resource is shared by the k8s cluster.
"owned" resource can not be used by other resources.
This seems necessary to allow the Amazon EKS service to know which AWS resources it should manage for the EKS cluster.(Not sure)
지금도 많이 간단해졌지만, EKS등 복잡한 object일 수록 이 module은 힘을 발휘하는 것 같다.
다만 customize/자유도가 좀 떨어지는 문제가 있을 것으로 보이는데, 직접 custom을 해야만하는 서비스를 만들 일은 별로 없을 것 같다..ㅎ