-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add full module configuration with examples
- Loading branch information
1 parent
61cc029
commit cb3c309
Showing
11 changed files
with
681 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.1.0 | ||
hooks: | ||
- id: check-added-large-files | ||
args: ['--maxkb=500'] | ||
- id: check-executables-have-shebangs | ||
- id: pretty-format-json | ||
args: ['--autofix', '--no-sort-keys', '--indent=2'] | ||
- id: check-byte-order-marker | ||
- id: check-case-conflict | ||
- id: check-executables-have-shebangs | ||
- id: check-merge-conflict | ||
- id: check-symlinks | ||
- id: detect-private-key | ||
- id: check-merge-conflict | ||
- id: detect-aws-credentials | ||
args: ['--allow-missing-credentials'] | ||
- id: trailing-whitespace | ||
- repo: git://github.com/antonbabenko/pre-commit-terraform | ||
rev: v1.64.0 | ||
hooks: | ||
- id: terraform_fmt | ||
- id: terraform_docs | ||
- id: terraform_tflint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
ifneq (,) | ||
.error This Makefile requires GNU Make. | ||
endif | ||
|
||
.PHONY: hooks validate changelog | ||
|
||
help: | ||
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
hooks: ## Commit hooks setup | ||
@pre-commit install | ||
@pre-commit gc | ||
@pre-commit autoupdate | ||
|
||
validate: ## Validate files with pre-commit hooks | ||
@pre-commit run --all-files | ||
|
||
changelog: | ||
git-chglog -o CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,81 @@ | ||
[![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) | ||
|
||
# terraform-aws-eks-node-group | ||
Terraform module to provision EKS Managed Node Group | ||
|
||
## Usage | ||
|
||
```hcl | ||
module "eks-node-group" { | ||
source = "native-cube/eks-node-group/aws" | ||
version = "~> 1.0.0" | ||
cluster_name = aws_eks_cluster.cluster.id | ||
node_group_name_prefix = "eks-cluster-" | ||
subnet_ids = ["subnet-1","subnet-2","subnet-3"] | ||
desired_size = 1 | ||
min_size = 1 | ||
max_size = 1 | ||
instance_types = ["t3.large","t2.large"] | ||
capacity_type = "SPOT" | ||
ec2_ssh_key = "eks-test" | ||
labels = { | ||
lifecycle = "Spot" | ||
} | ||
taints = [ | ||
{ | ||
key = "test-1" | ||
value = null | ||
effect = "NO_SCHEDULE" | ||
}, | ||
{ | ||
key = "test-2" | ||
value = "value-test" | ||
effect = "NO_EXECUTE" | ||
} | ||
] | ||
force_update_version = true | ||
tags = { | ||
Environment = "test" | ||
} | ||
} | ||
``` | ||
|
||
## Examples | ||
|
||
* [EKS Single Node Group](https://github.com/native-cube/terraform-aws-eks-node-group/tree/main/examples/single-node-group) | ||
* [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) | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
## License | ||
|
||
See LICENSE for full details. | ||
|
||
## Pre-commit hooks | ||
|
||
### Install dependencies | ||
|
||
* [`pre-commit`](https://pre-commit.com/#install) | ||
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks. | ||
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook. | ||
|
||
#### MacOS | ||
|
||
```bash | ||
brew install pre-commit terraform-docs tflint | ||
|
||
brew tap git-chglog/git-chglog | ||
brew install git-chglog | ||
``` |
142 changes: 142 additions & 0 deletions
142
examples/single-node-group-with-launch-template/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
##### | ||
# VPC and subnets | ||
##### | ||
data "aws_vpc" "default" { | ||
default = true | ||
} | ||
|
||
data "aws_subnets" "all" { | ||
filter { | ||
name = "vpc-id" | ||
values = [data.aws_vpc.default.id] | ||
} | ||
} | ||
|
||
##### | ||
# EKS Cluster | ||
##### | ||
resource "aws_eks_cluster" "cluster" { | ||
enabled_cluster_log_types = [] | ||
name = "eks-node-group-module-cluster" | ||
role_arn = aws_iam_role.cluster.arn | ||
version = "1.21" | ||
|
||
vpc_config { | ||
subnet_ids = data.aws_subnets.all.ids | ||
security_group_ids = [] | ||
endpoint_private_access = "true" | ||
endpoint_public_access = "true" | ||
} | ||
|
||
tags = { | ||
Environment = "test" | ||
Team = "" | ||
Service = "eks" | ||
Repository = "" | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "cluster" { | ||
name = "eks-node-group-module-cluster-role" | ||
|
||
assume_role_policy = jsonencode( | ||
{ | ||
"Version" : "2012-10-17", | ||
"Statement" : [ | ||
{ | ||
"Effect" : "Allow", | ||
"Principal" : { | ||
"Service" : "eks.amazonaws.com" | ||
}, | ||
"Action" : "sts:AssumeRole" | ||
} | ||
] | ||
} | ||
) | ||
|
||
managed_policy_arns = [ | ||
"arn:aws:iam::aws:policy/AmazonEKSClusterPolicy", | ||
"arn:aws:iam::aws:policy/AmazonEKSServicePolicy", | ||
"arn:aws:iam::aws:policy/AmazonEKSVPCResourceController" | ||
] | ||
} | ||
|
||
##### | ||
# Launch Template with AMI | ||
##### | ||
data "aws_ssm_parameter" "cluster" { | ||
name = "/aws/service/eks/optimized-ami/${aws_eks_cluster.cluster.version}/amazon-linux-2/recommended/image_id" | ||
} | ||
|
||
data "aws_launch_template" "cluster" { | ||
name = aws_launch_template.cluster.name | ||
|
||
depends_on = [aws_launch_template.cluster] | ||
} | ||
|
||
resource "aws_launch_template" "cluster" { | ||
image_id = data.aws_ssm_parameter.cluster.value | ||
instance_type = "t3.medium" | ||
name = "eks-node-group-launch-template" | ||
update_default_version = true | ||
|
||
key_name = "eks-test" | ||
|
||
block_device_mappings { | ||
device_name = "/dev/sda1" | ||
|
||
ebs { | ||
volume_size = 20 | ||
} | ||
} | ||
|
||
tag_specifications { | ||
resource_type = "instance" | ||
|
||
tags = { | ||
Name = "eks-node-group-instance-name" | ||
"kubernetes.io/cluster/eks-node-group-module-cluster" = "owned" | ||
} | ||
} | ||
|
||
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" })) | ||
} | ||
|
||
##### | ||
# EKS Node Group | ||
##### | ||
module "eks-node-group" { | ||
source = "../../" | ||
|
||
node_group_name_prefix = "eks-node-group-" | ||
|
||
cluster_name = aws_eks_cluster.cluster.id | ||
|
||
subnet_ids = data.aws_subnets.all.ids | ||
|
||
desired_size = 1 | ||
min_size = 1 | ||
max_size = 1 | ||
|
||
launch_template = { | ||
name = data.aws_launch_template.cluster.name | ||
version = data.aws_launch_template.cluster.latest_version | ||
} | ||
|
||
capacity_type = "SPOT" | ||
|
||
labels = { | ||
lifecycle = "Spot" | ||
} | ||
|
||
tags = { | ||
"kubernetes.io/cluster/eks-node-group-module-cluster" = "owned" | ||
Environment = "test" | ||
} | ||
|
||
depends_on = [data.aws_launch_template.cluster] | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/single-node-group-with-launch-template/userdata.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
MIME-Version: 1.0 | ||
Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" | ||
|
||
--==MYBOUNDARY== | ||
Content-Type: text/x-shellscript; charset="us-ascii" | ||
|
||
#!/bin/bash | ||
set -ex | ||
|
||
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 | ||
|
||
/etc/eks/bootstrap.sh ${CLUSTER_NAME} --b64-cluster-ca ${B64_CLUSTER_CA} --apiserver-endpoint ${API_SERVER_URL} --container-runtime ${CONTAINER_RUNTIME} | ||
|
||
--==MYBOUNDARY==-- |
Oops, something went wrong.