mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-03-20 16:43:46 +01:00
refactor: Refactoring to match the rest of terraform-aws-modules (#1583)
This commit is contained in:
247
examples/complete/main.tf
Normal file
247
examples/complete/main.tf
Normal file
@@ -0,0 +1,247 @@
|
||||
provider "aws" {
|
||||
region = local.region
|
||||
}
|
||||
|
||||
module "eks" {
|
||||
source = "../.."
|
||||
|
||||
cluster_name = local.cluster_name
|
||||
cluster_version = "1.21"
|
||||
|
||||
vpc_id = local.vpc.vpc_id
|
||||
subnets = [local.vpc.private_subnets[0], local.vpc.public_subnets[1]]
|
||||
fargate_subnets = [local.vpc.private_subnets[2]]
|
||||
|
||||
worker_additional_security_group_ids = [aws_security_group.all_worker_mgmt.id]
|
||||
|
||||
# Worker groups (using Launch Configurations)
|
||||
worker_groups = [
|
||||
{
|
||||
name = "worker-group-1"
|
||||
instance_type = "t3.small"
|
||||
additional_userdata = "echo foo bar"
|
||||
asg_desired_capacity = 2
|
||||
additional_security_group_ids = [aws_security_group.worker_group_mgmt_one.id]
|
||||
},
|
||||
{
|
||||
name = "worker-group-2"
|
||||
instance_type = "t3.medium"
|
||||
additional_userdata = "echo foo bar"
|
||||
additional_security_group_ids = [aws_security_group.worker_group_mgmt_two.id]
|
||||
asg_desired_capacity = 1
|
||||
},
|
||||
]
|
||||
|
||||
# Worker groups (using Launch Templates)
|
||||
worker_groups_launch_template = [
|
||||
{
|
||||
name = "spot-1"
|
||||
override_instance_types = ["m5.large", "m5a.large", "m5d.large", "m5ad.large"]
|
||||
spot_instance_pools = 4
|
||||
asg_max_size = 5
|
||||
asg_desired_capacity = 5
|
||||
kubelet_extra_args = "--node-labels=node.kubernetes.io/lifecycle=spot"
|
||||
public_ip = true
|
||||
},
|
||||
]
|
||||
|
||||
# Managed Node Groups
|
||||
node_groups_defaults = {
|
||||
ami_type = "AL2_x86_64"
|
||||
disk_size = 50
|
||||
}
|
||||
|
||||
node_groups = {
|
||||
example = {
|
||||
desired_capacity = 1
|
||||
max_capacity = 10
|
||||
min_capacity = 1
|
||||
|
||||
instance_types = ["t3.large"]
|
||||
capacity_type = "SPOT"
|
||||
k8s_labels = {
|
||||
Environment = "test"
|
||||
GithubRepo = "terraform-aws-eks"
|
||||
GithubOrg = "terraform-aws-modules"
|
||||
}
|
||||
additional_tags = {
|
||||
ExtraTag = "example"
|
||||
}
|
||||
taints = [
|
||||
{
|
||||
key = "dedicated"
|
||||
value = "gpuGroup"
|
||||
effect = "NO_SCHEDULE"
|
||||
}
|
||||
]
|
||||
update_config = {
|
||||
max_unavailable_percentage = 50 # or set `max_unavailable`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Fargate
|
||||
fargate_profiles = {
|
||||
default = {
|
||||
name = "default"
|
||||
selectors = [
|
||||
{
|
||||
namespace = "kube-system"
|
||||
labels = {
|
||||
k8s-app = "kube-dns"
|
||||
}
|
||||
},
|
||||
{
|
||||
namespace = "default"
|
||||
}
|
||||
]
|
||||
|
||||
tags = {
|
||||
Owner = "test"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# AWS Auth (kubernetes_config_map)
|
||||
map_roles = [
|
||||
{
|
||||
rolearn = "arn:aws:iam::66666666666:role/role1"
|
||||
username = "role1"
|
||||
groups = ["system:masters"]
|
||||
},
|
||||
]
|
||||
|
||||
map_users = [
|
||||
{
|
||||
userarn = "arn:aws:iam::66666666666:user/user1"
|
||||
username = "user1"
|
||||
groups = ["system:masters"]
|
||||
},
|
||||
{
|
||||
userarn = "arn:aws:iam::66666666666:user/user2"
|
||||
username = "user2"
|
||||
groups = ["system:masters"]
|
||||
},
|
||||
]
|
||||
|
||||
map_accounts = [
|
||||
"777777777777",
|
||||
"888888888888",
|
||||
]
|
||||
|
||||
tags = {
|
||||
Environment = "test"
|
||||
GithubRepo = "terraform-aws-eks"
|
||||
GithubOrg = "terraform-aws-modules"
|
||||
}
|
||||
}
|
||||
|
||||
####################
|
||||
# Disabled creation
|
||||
####################
|
||||
|
||||
module "disabled_eks" {
|
||||
source = "../.."
|
||||
|
||||
create_eks = false
|
||||
}
|
||||
|
||||
module "disabled_fargate" {
|
||||
source = "../../modules/fargate"
|
||||
|
||||
create_fargate_pod_execution_role = false
|
||||
}
|
||||
|
||||
module "disabled_node_groups" {
|
||||
source = "../../modules/node_groups"
|
||||
|
||||
create_eks = false
|
||||
}
|
||||
|
||||
#############
|
||||
# Kubernetes
|
||||
#############
|
||||
|
||||
data "aws_eks_cluster" "cluster" {
|
||||
name = module.eks.cluster_id
|
||||
}
|
||||
|
||||
data "aws_eks_cluster_auth" "cluster" {
|
||||
name = module.eks.cluster_id
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
host = data.aws_eks_cluster.cluster.endpoint
|
||||
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data)
|
||||
token = data.aws_eks_cluster_auth.cluster.token
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Supporting resources
|
||||
################################################################################
|
||||
|
||||
resource "aws_security_group" "worker_group_mgmt_one" {
|
||||
name_prefix = "worker_group_mgmt_one"
|
||||
vpc_id = local.vpc.vpc_id
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
|
||||
cidr_blocks = [
|
||||
"10.0.0.0/8",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "worker_group_mgmt_two" {
|
||||
name_prefix = "worker_group_mgmt_two"
|
||||
vpc_id = local.vpc.vpc_id
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
|
||||
cidr_blocks = [
|
||||
"192.168.0.0/16",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "all_worker_mgmt" {
|
||||
name_prefix = "all_worker_management"
|
||||
vpc_id = local.vpc.vpc_id
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
|
||||
cidr_blocks = [
|
||||
"10.0.0.0/8",
|
||||
"172.16.0.0/12",
|
||||
"192.168.0.0/16",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
################################################################################
|
||||
# Supporting resources (managed in "_bootstrap" directory)
|
||||
################################################################################
|
||||
|
||||
data "terraform_remote_state" "bootstrap" {
|
||||
backend = "local"
|
||||
|
||||
config = {
|
||||
path = "../_bootstrap/terraform.tfstate"
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
region = data.terraform_remote_state.bootstrap.outputs.region
|
||||
cluster_name = data.terraform_remote_state.bootstrap.outputs.cluster_name
|
||||
vpc = data.terraform_remote_state.bootstrap.outputs.vpc
|
||||
}
|
||||
Reference in New Issue
Block a user