Skip to content

Commit cb3c309

Browse files
committed
Add full module configuration with examples
1 parent 61cc029 commit cb3c309

File tree

11 files changed

+681
-0
lines changed

11 files changed

+681
-0
lines changed

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: check-added-large-files
6+
args: ['--maxkb=500']
7+
- id: check-executables-have-shebangs
8+
- id: pretty-format-json
9+
args: ['--autofix', '--no-sort-keys', '--indent=2']
10+
- id: check-byte-order-marker
11+
- id: check-case-conflict
12+
- id: check-executables-have-shebangs
13+
- id: check-merge-conflict
14+
- id: check-symlinks
15+
- id: detect-private-key
16+
- id: check-merge-conflict
17+
- id: detect-aws-credentials
18+
args: ['--allow-missing-credentials']
19+
- id: trailing-whitespace
20+
- repo: git://github.com/antonbabenko/pre-commit-terraform
21+
rev: v1.64.0
22+
hooks:
23+
- id: terraform_fmt
24+
- id: terraform_docs
25+
- id: terraform_tflint

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ifneq (,)
2+
.error This Makefile requires GNU Make.
3+
endif
4+
5+
.PHONY: hooks validate changelog
6+
7+
help:
8+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
9+
10+
hooks: ## Commit hooks setup
11+
@pre-commit install
12+
@pre-commit gc
13+
@pre-commit autoupdate
14+
15+
validate: ## Validate files with pre-commit hooks
16+
@pre-commit run --all-files
17+
18+
changelog:
19+
git-chglog -o CHANGELOG.md

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,81 @@
1+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/native-cube/terraform-aws-eks-node-group)](https://github.com/native-cube/terraform-aws-eks-node-group/releases/latest)
2+
13
# terraform-aws-eks-node-group
24
Terraform module to provision EKS Managed Node Group
5+
6+
## Usage
7+
8+
```hcl
9+
module "eks-node-group" {
10+
source = "native-cube/eks-node-group/aws"
11+
version = "~> 1.0.0"
12+
13+
cluster_name = aws_eks_cluster.cluster.id
14+
15+
node_group_name_prefix = "eks-cluster-"
16+
17+
subnet_ids = ["subnet-1","subnet-2","subnet-3"]
18+
19+
desired_size = 1
20+
min_size = 1
21+
max_size = 1
22+
23+
instance_types = ["t3.large","t2.large"]
24+
capacity_type = "SPOT"
25+
26+
ec2_ssh_key = "eks-test"
27+
28+
labels = {
29+
lifecycle = "Spot"
30+
}
31+
32+
taints = [
33+
{
34+
key = "test-1"
35+
value = null
36+
effect = "NO_SCHEDULE"
37+
},
38+
{
39+
key = "test-2"
40+
value = "value-test"
41+
effect = "NO_EXECUTE"
42+
}
43+
]
44+
45+
force_update_version = true
46+
47+
tags = {
48+
Environment = "test"
49+
}
50+
}
51+
```
52+
53+
## Examples
54+
55+
* [EKS Single Node Group](https://github.com/native-cube/terraform-aws-eks-node-group/tree/main/examples/single-node-group)
56+
* [EKS Single Node Group with Launch Template](https://github.com/native-cube/terraform-aws-eks-node-group/tree/main/examples/single-node-group-with-launch-template)
57+
58+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
59+
60+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
61+
62+
## License
63+
64+
See LICENSE for full details.
65+
66+
## Pre-commit hooks
67+
68+
### Install dependencies
69+
70+
* [`pre-commit`](https://pre-commit.com/#install)
71+
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks.
72+
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.
73+
74+
#### MacOS
75+
76+
```bash
77+
brew install pre-commit terraform-docs tflint
78+
79+
brew tap git-chglog/git-chglog
80+
brew install git-chglog
81+
```
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
#####
6+
# VPC and subnets
7+
#####
8+
data "aws_vpc" "default" {
9+
default = true
10+
}
11+
12+
data "aws_subnets" "all" {
13+
filter {
14+
name = "vpc-id"
15+
values = [data.aws_vpc.default.id]
16+
}
17+
}
18+
19+
#####
20+
# EKS Cluster
21+
#####
22+
resource "aws_eks_cluster" "cluster" {
23+
enabled_cluster_log_types = []
24+
name = "eks-node-group-module-cluster"
25+
role_arn = aws_iam_role.cluster.arn
26+
version = "1.21"
27+
28+
vpc_config {
29+
subnet_ids = data.aws_subnets.all.ids
30+
security_group_ids = []
31+
endpoint_private_access = "true"
32+
endpoint_public_access = "true"
33+
}
34+
35+
tags = {
36+
Environment = "test"
37+
Team = ""
38+
Service = "eks"
39+
Repository = ""
40+
}
41+
}
42+
43+
resource "aws_iam_role" "cluster" {
44+
name = "eks-node-group-module-cluster-role"
45+
46+
assume_role_policy = jsonencode(
47+
{
48+
"Version" : "2012-10-17",
49+
"Statement" : [
50+
{
51+
"Effect" : "Allow",
52+
"Principal" : {
53+
"Service" : "eks.amazonaws.com"
54+
},
55+
"Action" : "sts:AssumeRole"
56+
}
57+
]
58+
}
59+
)
60+
61+
managed_policy_arns = [
62+
"arn:aws:iam::aws:policy/AmazonEKSClusterPolicy",
63+
"arn:aws:iam::aws:policy/AmazonEKSServicePolicy",
64+
"arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
65+
]
66+
}
67+
68+
#####
69+
# Launch Template with AMI
70+
#####
71+
data "aws_ssm_parameter" "cluster" {
72+
name = "/aws/service/eks/optimized-ami/${aws_eks_cluster.cluster.version}/amazon-linux-2/recommended/image_id"
73+
}
74+
75+
data "aws_launch_template" "cluster" {
76+
name = aws_launch_template.cluster.name
77+
78+
depends_on = [aws_launch_template.cluster]
79+
}
80+
81+
resource "aws_launch_template" "cluster" {
82+
image_id = data.aws_ssm_parameter.cluster.value
83+
instance_type = "t3.medium"
84+
name = "eks-node-group-launch-template"
85+
update_default_version = true
86+
87+
key_name = "eks-test"
88+
89+
block_device_mappings {
90+
device_name = "/dev/sda1"
91+
92+
ebs {
93+
volume_size = 20
94+
}
95+
}
96+
97+
tag_specifications {
98+
resource_type = "instance"
99+
100+
tags = {
101+
Name = "eks-node-group-instance-name"
102+
"kubernetes.io/cluster/eks-node-group-module-cluster" = "owned"
103+
}
104+
}
105+
106+
user_data = base64encode(templatefile("userdata.tpl", { CLUSTER_NAME = aws_eks_cluster.cluster.name, B64_CLUSTER_CA = aws_eks_cluster.cluster.certificate_authority[0].data, API_SERVER_URL = aws_eks_cluster.cluster.endpoint, CONTAINER_RUNTIME = "containerd" }))
107+
}
108+
109+
#####
110+
# EKS Node Group
111+
#####
112+
module "eks-node-group" {
113+
source = "../../"
114+
115+
node_group_name_prefix = "eks-node-group-"
116+
117+
cluster_name = aws_eks_cluster.cluster.id
118+
119+
subnet_ids = data.aws_subnets.all.ids
120+
121+
desired_size = 1
122+
min_size = 1
123+
max_size = 1
124+
125+
launch_template = {
126+
name = data.aws_launch_template.cluster.name
127+
version = data.aws_launch_template.cluster.latest_version
128+
}
129+
130+
capacity_type = "SPOT"
131+
132+
labels = {
133+
lifecycle = "Spot"
134+
}
135+
136+
tags = {
137+
"kubernetes.io/cluster/eks-node-group-module-cluster" = "owned"
138+
Environment = "test"
139+
}
140+
141+
depends_on = [data.aws_launch_template.cluster]
142+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
MIME-Version: 1.0
2+
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="
3+
4+
--==MYBOUNDARY==
5+
Content-Type: text/x-shellscript; charset="us-ascii"
6+
7+
#!/bin/bash
8+
set -ex
9+
10+
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
11+
12+
/etc/eks/bootstrap.sh ${CLUSTER_NAME} --b64-cluster-ca ${B64_CLUSTER_CA} --apiserver-endpoint ${API_SERVER_URL} --container-runtime ${CONTAINER_RUNTIME}
13+
14+
--==MYBOUNDARY==--

0 commit comments

Comments
 (0)