Skip to content

Commit 610a538

Browse files
authored
Initial implementation of terraform-aws-eks-node-group (#1)
* Initial implementation. Add tests. Add Codefresh test pipeline * Initial implementation. Add tests. Add Codefresh test pipeline * Initial implementation. Add tests. Add Codefresh test pipeline * Initial implementation. Add tests. Add Codefresh test pipeline * Initial implementation. Add tests. Add Codefresh test pipeline * Initial implementation. Add tests. Add Codefresh test pipeline * Initial implementation. Add tests. Add Codefresh test pipeline * Increase test timeout
1 parent 9d624a0 commit 610a538

25 files changed

+1590
-5
lines changed

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
*.tfstate
66
*.tfstate.*
77

8-
# .tfvars files
9-
*.tfvars
8+
**/.idea
9+
**/*.iml
10+
11+
**/.build-harness
12+
**/build-harness
13+
14+
# vim editor
15+
*.swp

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2019 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SHELL := /bin/bash
2+
3+
# List of targets the `readme` target should call before generating the readme
4+
export README_DEPS ?= docs/targets.md docs/terraform.md
5+
6+
-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness)
7+
8+
## Lint terraform code
9+
lint:
10+
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate

README.md

Lines changed: 423 additions & 2 deletions
Large diffs are not rendered by default.

README.yaml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
#
3+
# This is the canonical configuration for the `README.md`
4+
# Run `make readme` to rebuild the `README.md`
5+
#
6+
7+
# Name of this project
8+
name: terraform-aws-eks-node-group
9+
10+
# Logo for this project
11+
#logo: docs/logo.png
12+
13+
# License of this project
14+
license: "APACHE2"
15+
16+
# Canonical GitHub repo
17+
github_repo: cloudposse/terraform-aws-eks-node-group
18+
19+
# Badges to display
20+
badges:
21+
- name: "Codefresh Build Status"
22+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-eks-node-group?type=cf-1"
23+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5dead6c731a1a7177ed48f8e"
24+
- name: "Latest Release"
25+
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-eks-node-group.svg"
26+
url: "https://github.com/cloudposse/terraform-aws-eks-node-group/releases/latest"
27+
- name: "Slack Community"
28+
image: "https://slack.cloudposse.com/badge.svg"
29+
url: "https://slack.cloudposse.com"
30+
31+
related:
32+
- name: "terraform-aws-eks-cluster"
33+
description: "Terraform module to provision an EKS cluster on AWS"
34+
url: "https://github.com/cloudposse/terraform-aws-eks-cluster"
35+
- name: "terraform-aws-eks-workers"
36+
description: "Terraform module to provision an AWS AutoScaling Group, IAM Role, and Security Group for EKS Workers"
37+
url: "https://github.com/cloudposse/terraform-aws-eks-workers"
38+
- name: "terraform-aws-ec2-autoscale-group"
39+
description: "Terraform module to provision Auto Scaling Group and Launch Template on AWS"
40+
url: "https://github.com/cloudposse/terraform-aws-ec2-autoscale-group"
41+
- name: "terraform-aws-ecs-container-definition"
42+
description: "Terraform module to generate well-formed JSON documents (container definitions) that are passed to the aws_ecs_task_definition Terraform resource"
43+
url: "https://github.com/cloudposse/terraform-aws-ecs-container-definition"
44+
- name: "terraform-aws-ecs-alb-service-task"
45+
description: "Terraform module which implements an ECS service which exposes a web service via ALB"
46+
url: "https://github.com/cloudposse/terraform-aws-ecs-alb-service-task"
47+
- name: "terraform-aws-ecs-web-app"
48+
description: "Terraform module that implements a web app on ECS and supports autoscaling, CI/CD, monitoring, ALB integration, and much more"
49+
url: "https://github.com/cloudposse/terraform-aws-ecs-web-app"
50+
- name: "terraform-aws-ecs-codepipeline"
51+
description: "Terraform module for CI/CD with AWS Code Pipeline and Code Build for ECS"
52+
url: "https://github.com/cloudposse/terraform-aws-ecs-codepipeline"
53+
- name: "terraform-aws-ecs-cloudwatch-autoscaling"
54+
description: "Terraform module to autoscale ECS Service based on CloudWatch metrics"
55+
url: "https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-autoscaling"
56+
- name: "terraform-aws-ecs-cloudwatch-sns-alarms"
57+
description: "Terraform module to create CloudWatch Alarms on ECS Service level metrics"
58+
url: "https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms"
59+
- name: "terraform-aws-ec2-instance"
60+
description: "Terraform module for providing a general purpose EC2 instance"
61+
url: "https://github.com/cloudposse/terraform-aws-ec2-instance"
62+
- name: "terraform-aws-ec2-instance-group"
63+
description: "Terraform module for provisioning multiple general purpose EC2 hosts for stateful applications"
64+
url: "https://github.com/cloudposse/terraform-aws-ec2-instance-group"
65+
66+
# Short description of this project
67+
description: |-
68+
Terraform module to provision an EKS Node Group for [Elastic Container Service for Kubernetes](https://aws.amazon.com/eks/).
69+
70+
Instantiate it multiple times to create many EKS node groups with specific settings such as GPUs, EC2 instance types, or autoscale parameters.
71+
72+
introduction: |-
73+
74+
# How to use this project
75+
usage: |-
76+
77+
For a complete example, see [examples/complete](examples/complete).
78+
79+
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS), see [test](test).
80+
81+
```hcl
82+
provider "aws" {
83+
region = var.region
84+
}
85+
86+
module "label" {
87+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
88+
namespace = var.namespace
89+
name = var.name
90+
stage = var.stage
91+
delimiter = var.delimiter
92+
attributes = compact(concat(var.attributes, list("cluster")))
93+
tags = var.tags
94+
}
95+
96+
locals {
97+
tags = merge(module.label.tags, map("kubernetes.io/cluster/${module.label.id}", "shared"))
98+
}
99+
100+
module "vpc" {
101+
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.1"
102+
namespace = var.namespace
103+
stage = var.stage
104+
name = var.name
105+
attributes = var.attributes
106+
cidr_block = var.vpc_cidr_block
107+
tags = local.tags
108+
}
109+
110+
module "subnets" {
111+
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.18.1"
112+
availability_zones = var.availability_zones
113+
namespace = var.namespace
114+
stage = var.stage
115+
name = var.name
116+
attributes = var.attributes
117+
vpc_id = module.vpc.vpc_id
118+
igw_id = module.vpc.igw_id
119+
cidr_block = module.vpc.vpc_cidr_block
120+
nat_gateway_enabled = false
121+
nat_instance_enabled = false
122+
tags = local.tags
123+
}
124+
125+
module "eks_cluster" {
126+
source = "git::https://github.com/cloudposse/terraform-aws-eks-cluster.git?ref=tags/0.13.0"
127+
namespace = var.namespace
128+
stage = var.stage
129+
name = var.name
130+
attributes = var.attributes
131+
tags = var.tags
132+
region = var.region
133+
vpc_id = module.vpc.vpc_id
134+
subnet_ids = module.subnets.public_subnet_ids
135+
kubernetes_version = var.kubernetes_version
136+
kubeconfig_path = var.kubeconfig_path
137+
oidc_provider_enabled = var.oidc_provider_enabled
138+
139+
workers_role_arns = [module.eks_node_group.eks_node_group_role_arn]
140+
workers_security_group_ids = []
141+
}
142+
143+
module "eks_node_group" {
144+
source = "git::https://github.com/cloudposse/terraform-aws-eks-node-group.git?ref=master"
145+
namespace = var.namespace
146+
stage = var.stage
147+
name = var.name
148+
attributes = var.attributes
149+
tags = var.tags
150+
vpc_id = module.vpc.vpc_id
151+
subnet_ids = module.subnets.public_subnet_ids
152+
instance_types = var.instance_types
153+
desired_size = var.desired_size
154+
min_size = var.min_size
155+
max_size = var.max_size
156+
cluster_name = module.eks_cluster.eks_cluster_id
157+
kubernetes_version = var.kubernetes_version
158+
}
159+
```
160+
161+
include:
162+
- "docs/targets.md"
163+
- "docs/terraform.md"
164+
165+
# Contributors to this project
166+
contributors:
167+
- name: "Erik Osterman"
168+
github: "osterman"
169+
- name: "Andriy Knysh"
170+
github: "aknysh"
171+
- name: "Igor Rodionov"
172+
github: "goruha"

codefresh/test.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Prepare
5+
- Test
6+
7+
steps:
8+
wait:
9+
title: Wait
10+
stage: Prepare
11+
image: codefresh/cli:latest
12+
commands:
13+
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
14+
retry:
15+
maxAttempts: 10
16+
delay: 20
17+
exponentialFactor: 1.1
18+
19+
main_clone:
20+
title: "Clone repository"
21+
type: git-clone
22+
stage: Prepare
23+
description: "Initialize"
24+
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
25+
git: CF-default
26+
revision: ${{CF_REVISION}}
27+
28+
clean_init:
29+
title: Prepare build-harness and test-harness
30+
image: ${{TEST_IMAGE}}
31+
stage: Prepare
32+
commands:
33+
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
34+
- make init
35+
- git -C build-harness checkout master
36+
- make -C test/ clean init TEST_HARNESS_BRANCH=master
37+
- make -C test/src clean init
38+
- find . -type d -name '.terraform' | xargs rm -rf
39+
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;
40+
41+
test:
42+
type: "parallel"
43+
title: "Run tests"
44+
description: "Run all tests in parallel"
45+
stage: Test
46+
steps:
47+
test_readme_lint:
48+
title: "Test README.md updated"
49+
stage: "Test"
50+
image: ${{TEST_IMAGE}}
51+
description: Test "readme/lint"
52+
commands:
53+
- make readme/lint
54+
55+
test_module:
56+
title: Test module with bats
57+
image: ${{TEST_IMAGE}}
58+
stage: Test
59+
commands:
60+
- make -C test/ module
61+
62+
test_examples_complete:
63+
title: Test "examples/complete" with bats
64+
image: ${{TEST_IMAGE}}
65+
stage: Test
66+
commands:
67+
- make -C test/ examples/complete
68+
69+
test_examples_complete_terratest:
70+
title: Test "examples/complete" with terratest
71+
image: ${{TEST_IMAGE}}
72+
stage: Test
73+
commands:
74+
- unset AWS_PROFILE
75+
- unset AWS_DEFAULT_PROFILE
76+
- unset AWS_MFA_PROFILE
77+
- make -C test/src

docs/targets.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Makefile Targets
2+
```
3+
Available targets:
4+
5+
help Help screen
6+
help/all Display help for all targets
7+
help/short This help short screen
8+
lint Lint terraform code
9+
10+
```

docs/terraform.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Inputs
2+
3+
| Name | Description | Type | Default | Required |
4+
|------|-------------|:----:|:-----:|:-----:|
5+
| ami_release_version | AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version | string | `null` | no |
6+
| ami_type | Type of Amazon Machine Image (AMI) associated with the EKS Node Group. Defaults to `AL2_x86_64`. Valid values: `AL2_x86_64`, `AL2_x86_64_GPU`. Terraform will only perform drift detection if a configuration value is provided | string | `AL2_x86_64` | no |
7+
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
8+
| cluster_name | The name of the EKS cluster | string | - | yes |
9+
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
10+
| desired_size | Desired number of worker nodes | number | - | yes |
11+
| disk_size | Disk size in GiB for worker nodes. Defaults to 20. Terraform will only perform drift detection if a configuration value is provided | number | `20` | no |
12+
| ec2_ssh_key | SSH key name that should be used to access the worker nodes | string | `null` | no |
13+
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | bool | `true` | no |
14+
| existing_workers_role_policy_arns | List of existing policy ARNs that will be attached to the workers default role on creation | list(string) | `<list>` | no |
15+
| existing_workers_role_policy_arns_count | Count of existing policy ARNs that will be attached to the workers default role on creation. Needed to prevent Terraform error `count can't be computed` | number | `0` | no |
16+
| instance_types | Set of instance types associated with the EKS Node Group. Defaults to ["t3.medium"]. Terraform will only perform drift detection if a configuration value is provided | list(string) | - | yes |
17+
| kubernetes_labels | Key-value mapping of Kubernetes labels. Only labels that are applied with the EKS API are managed by this argument. Other Kubernetes labels applied to the EKS Node Group will not be managed | map(string) | `<map>` | no |
18+
| kubernetes_version | Kubernetes version. Defaults to EKS Cluster Kubernetes version. Terraform will only perform drift detection if a configuration value is provided | string | `null` | no |
19+
| max_size | Maximum number of worker nodes | number | - | yes |
20+
| min_size | Minimum number of worker nodes | number | - | yes |
21+
| name | Solution name, e.g. 'app' or 'cluster' | string | - | yes |
22+
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
23+
| source_security_group_ids | Set of EC2 Security Group IDs to allow SSH access (port 22) from on the worker nodes. If you specify `ec2_ssh_key`, but do not specify this configuration when you create an EKS Node Group, port 22 on the worker nodes is opened to the Internet (0.0.0.0/0) | list(string) | `<list>` | no |
24+
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
25+
| subnet_ids | A list of subnet IDs to launch resources in | list(string) | - | yes |
26+
| tags | Additional tags (e.g. `{ BusinessUnit = "XYZ" }` | map(string) | `<map>` | no |
27+
28+
## Outputs
29+
30+
| Name | Description |
31+
|------|-------------|
32+
| eks_node_group_arn | Amazon Resource Name (ARN) of the EKS Node Group |
33+
| eks_node_group_id | EKS Cluster name and EKS Node Group name separated by a colon |
34+
| eks_node_group_resources | List of objects containing information about underlying resources of the EKS Node Group |
35+
| eks_node_group_role_arn | ARN of the worker nodes IAM role |
36+
| eks_node_group_role_name | Name of the worker nodes IAM role |
37+
| eks_node_group_status | Status of the EKS Node Group |
38+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
region = "us-east-2"
2+
3+
availability_zones = ["us-east-2a", "us-east-2b"]
4+
5+
vpc_cidr_block = "172.16.0.0/16"
6+
7+
namespace = "eg"
8+
9+
stage = "test"
10+
11+
name = "eks-node-group"
12+
13+
instance_types = ["t3.small"]
14+
15+
desired_size = 2
16+
17+
max_size = 3
18+
19+
min_size = 2
20+
21+
disk_size = 20
22+
23+
kubeconfig_path = "/.kube/config"
24+
25+
kubernetes_labels = {}

0 commit comments

Comments
 (0)