Skip to content

Commit 052c59c

Browse files
authored
Adding support for environment input/label (#21)
* Adding support for environment input/label * Fixing type on environment input & generating README.md the properly * Fixing the tests! * Fixing more tests! * Reverting previous package version in tests * Pinning client-go dependency in tests * Updating tests to bring it up to date with terraform-aws-eks-cluster * Fixing small issue in test * Fixing test example & updating Go package deps * One more final tweak in test logic to fix expected cluster name value
1 parent f57b87b commit 052c59c

File tree

16 files changed

+891
-236
lines changed

16 files changed

+891
-236
lines changed

README.md

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
<!--
2-
3-
4-
5-
6-
7-
8-
1+
# terraform-aws-eks-node-group [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-eks-node-group.svg)](https://github.com/cloudposse/terraform-aws-eks-node-group/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
92

3+
[![README Header][readme_header_img]][readme_header_link]
104

5+
[![Cloud Posse][logo]](https://cpco.io/homepage)
116

7+
<!--
128
139
1410
1511
1612
** DO NOT EDIT THIS FILE
17-
**
18-
** This file was automatically generated by the `build-harness`.
19-
** 1) Make all changes to `README.yaml`
13+
**
14+
** This file was automatically generated by the `build-harness`.
15+
** 1) Make all changes to `README.yaml`
2016
** 2) Run `make init` (you only need to do this once)
21-
** 3) Run`make readme` to rebuild this file.
17+
** 3) Run`make readme` to rebuild this file.
2218
**
2319
** (We maintain HUNDREDS of open source projects. This is how we maintain our sanity.)
2420
**
@@ -27,23 +23,7 @@
2723
2824
2925
30-
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
-->
41-
[![README Header][readme_header_img]][readme_header_link]
42-
43-
[![Cloud Posse][logo]](https://cpco.io/homepage)
44-
45-
# terraform-aws-eks-node-group [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-eks-node-group.svg)](https://github.com/cloudposse/terraform-aws-eks-node-group/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
46-
26+
-->
4727

4828
Terraform module to provision an EKS Node Group for [Elastic Container Service for Kubernetes](https://aws.amazon.com/eks/).
4929

@@ -52,7 +32,7 @@ Instantiate it multiple times to create many EKS node groups with specific setti
5232

5333
---
5434

55-
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
35+
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
5636
[<img align="right" title="Share via Email" src="https://docs.cloudposse.com/images/ionicons/ios-email-outline-2.0.1-16x16-999999.svg"/>][share_email]
5737
[<img align="right" title="Share on Google+" src="https://docs.cloudposse.com/images/ionicons/social-googleplus-outline-2.0.1-16x16-999999.svg" />][share_googleplus]
5838
[<img align="right" title="Share on Facebook" src="https://docs.cloudposse.com/images/ionicons/social-facebook-outline-2.0.1-16x16-999999.svg" />][share_facebook]
@@ -73,7 +53,7 @@ It's 100% Open Source and licensed under the [APACHE2](LICENSE).
7353

7454

7555

76-
We literally have [*hundreds of terraform modules*][terraform_modules] that are Open Source and well-maintained. Check them out!
56+
We literally have [*hundreds of terraform modules*][terraform_modules] that are Open Source and well-maintained. Check them out!
7757

7858

7959

@@ -180,8 +160,9 @@ For automated tests of the complete example using [bats](https://github.com/bats
180160

181161

182162

163+
<!-- markdownlint-disable -->
183164
## Makefile Targets
184-
```
165+
```text
185166
Available targets:
186167
187168
help Help screen
@@ -190,6 +171,7 @@ Available targets:
190171
lint Lint terraform code
191172
192173
```
174+
<!-- markdownlint-restore -->
193175
## Requirements
194176

195177
| Name | Version |
@@ -219,6 +201,7 @@ Available targets:
219201
| ec2\_ssh\_key | SSH key name that should be used to access the worker nodes | `string` | `null` | no |
220202
| enable\_cluster\_autoscaler | Whether to enable node group to scale the Auto Scaling Group | `bool` | `false` | no |
221203
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | `bool` | `true` | no |
204+
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | `string` | `""` | no |
222205
| existing\_workers\_role\_policy\_arns | List of existing policy ARNs that will be attached to the workers default role on creation | `list(string)` | `[]` | no |
223206
| 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 |
224207
| 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)` | n/a | yes |
@@ -248,9 +231,9 @@ Available targets:
248231

249232

250233

251-
## Share the Love
234+
## Share the Love
252235

253-
Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-eks-node-group)! (it helps us **a lot**)
236+
Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-eks-node-group)! (it helps us **a lot**)
254237

255238
Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =)
256239

@@ -275,7 +258,7 @@ Check out these related projects.
275258

276259
## Help
277260

278-
**Got a question?** We got answers.
261+
**Got a question?** We got answers.
279262

280263
File a GitHub [issue](https://github.com/cloudposse/terraform-aws-eks-node-group/issues), send us an [email][email] or join our [Slack Community][slack].
281264

@@ -284,7 +267,7 @@ File a GitHub [issue](https://github.com/cloudposse/terraform-aws-eks-node-group
284267
## DevOps Accelerator for Startups
285268

286269

287-
We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.
270+
We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.
288271

289272
[![Learn More](https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge)][commercial_support]
290273

@@ -313,11 +296,11 @@ Participate in our [Discourse Forums][discourse]. Here you'll find answers to co
313296

314297
## Newsletter
315298

316-
Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
299+
Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
317300

318301
## Office Hours
319302

320-
[Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone!
303+
[Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone!
321304

322305
[![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours]
323306

@@ -348,9 +331,9 @@ Copyright © 2017-2020 [Cloud Posse, LLC](https://cpco.io/copyright)
348331

349332

350333

351-
## License
334+
## License
352335

353-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
336+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
354337

355338
See [LICENSE](LICENSE) for full details.
356339

@@ -391,7 +374,7 @@ This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? P
391374

392375
We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We ❤️ [Open Source Software][we_love_open_source].
393376

394-
We offer [paid support][commercial_support] on all of our projects.
377+
We offer [paid support][commercial_support] on all of our projects.
395378

396379
Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.
397380

docs/targets.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
<!-- markdownlint-disable -->
12
## Makefile Targets
2-
```
3+
```text
34
Available targets:
45
56
help Help screen
@@ -8,3 +9,4 @@ Available targets:
89
lint Lint terraform code
910
1011
```
12+
<!-- markdownlint-restore -->

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| ec2\_ssh\_key | SSH key name that should be used to access the worker nodes | `string` | `null` | no |
2828
| enable\_cluster\_autoscaler | Whether to enable node group to scale the Auto Scaling Group | `bool` | `false` | no |
2929
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | `bool` | `true` | no |
30+
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | `string` | `""` | no |
3031
| existing\_workers\_role\_policy\_arns | List of existing policy ARNs that will be attached to the workers default role on creation | `list(string)` | `[]` | no |
3132
| 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 |
3233
| 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)` | n/a | yes |

examples/complete/fixtures.us-east-2.tfvars

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ stage = "test"
1010

1111
name = "eks-node-group"
1212

13+
kubernetes_version = "1.15"
14+
15+
oidc_provider_enabled = true
16+
17+
enabled_cluster_log_types = ["audit"]
18+
19+
cluster_log_retention_period = 7
20+
1321
instance_types = ["t3.small"]
1422

1523
desired_size = 2
@@ -20,6 +28,4 @@ min_size = 2
2028

2129
disk_size = 20
2230

23-
kubeconfig_path = "/.kube/config"
24-
2531
kubernetes_labels = {}

examples/complete/main.tf

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ module "label" {
1313
}
1414

1515
locals {
16+
# The usage of the specific kubernetes.io/cluster/* resource tags below are required
17+
# for EKS and Kubernetes to discover and manage networking resources
18+
# https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html#base-vpc-networking
1619
tags = merge(module.label.tags, map("kubernetes.io/cluster/${module.label.id}", "shared"))
20+
21+
# Unfortunately, most_recent (https://github.com/cloudposse/terraform-aws-eks-workers/blob/34a43c25624a6efb3ba5d2770a601d7cb3c0d391/main.tf#L141)
22+
# variable does not work as expected, if you are not going to use custom ami you should
23+
# enforce usage of eks_worker_ami_name_filter variable to set the right kubernetes version for EKS workers,
24+
# otherwise will be used the first version of Kubernetes supported by AWS (v1.11) for EKS workers but
25+
# EKS control plane will use the version specified by kubernetes_version variable.
26+
eks_worker_ami_name_filter = "amazon-eks-node-${var.kubernetes_version}*"
1727
}
1828

1929
module "vpc" {
@@ -22,12 +32,12 @@ module "vpc" {
2232
stage = var.stage
2333
name = var.name
2434
attributes = var.attributes
25-
cidr_block = var.vpc_cidr_block
35+
cidr_block = "172.16.0.0/16"
2636
tags = local.tags
2737
}
2838

2939
module "subnets" {
30-
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.18.1"
40+
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.19.0"
3141
availability_zones = var.availability_zones
3242
namespace = var.namespace
3343
stage = var.stage
@@ -42,21 +52,32 @@ module "subnets" {
4252
}
4353

4454
module "eks_cluster" {
45-
source = "git::https://github.com/cloudposse/terraform-aws-eks-cluster.git?ref=tags/0.16.0"
46-
namespace = var.namespace
47-
stage = var.stage
48-
name = var.name
49-
attributes = var.attributes
50-
tags = var.tags
51-
region = var.region
52-
vpc_id = module.vpc.vpc_id
53-
subnet_ids = module.subnets.public_subnet_ids
54-
kubernetes_version = var.kubernetes_version
55-
kubeconfig_path = var.kubeconfig_path
56-
oidc_provider_enabled = var.oidc_provider_enabled
55+
source = "git::https://github.com/cloudposse/terraform-aws-eks-cluster.git?ref=tags/0.24.0"
56+
namespace = var.namespace
57+
stage = var.stage
58+
name = var.name
59+
attributes = var.attributes
60+
tags = var.tags
61+
region = var.region
62+
vpc_id = module.vpc.vpc_id
63+
subnet_ids = module.subnets.public_subnet_ids
64+
kubernetes_version = var.kubernetes_version
65+
local_exec_interpreter = var.local_exec_interpreter
66+
oidc_provider_enabled = var.oidc_provider_enabled
67+
enabled_cluster_log_types = var.enabled_cluster_log_types
68+
cluster_log_retention_period = var.cluster_log_retention_period
69+
}
5770

58-
workers_role_arns = [module.eks_node_group.eks_node_group_role_arn]
59-
workers_security_group_ids = []
71+
# Ensure ordering of resource creation to eliminate the race conditions when applying the Kubernetes Auth ConfigMap.
72+
# Do not create Node Group before the EKS cluster is created and the `aws-auth` Kubernetes ConfigMap is applied.
73+
# Otherwise, EKS will create the ConfigMap first and add the managed node role ARNs to it,
74+
# and the kubernetes provider will throw an error that the ConfigMap already exists (because it can't update the map, only create it).
75+
# If we create the ConfigMap first (to add additional roles/users/accounts), EKS will just update it by adding the managed node role ARNs.
76+
data "null_data_source" "wait_for_cluster_and_kubernetes_configmap" {
77+
inputs = {
78+
cluster_name = module.eks_cluster.eks_cluster_id
79+
kubernetes_config_map_id = module.eks_cluster.kubernetes_config_map_id
80+
}
6081
}
6182

6283
module "eks_node_group" {
@@ -67,11 +88,11 @@ module "eks_node_group" {
6788
attributes = var.attributes
6889
tags = var.tags
6990
subnet_ids = module.subnets.public_subnet_ids
91+
cluster_name = data.null_data_source.wait_for_cluster_and_kubernetes_configmap.outputs["cluster_name"]
7092
instance_types = var.instance_types
7193
desired_size = var.desired_size
7294
min_size = var.min_size
7395
max_size = var.max_size
74-
cluster_name = module.eks_cluster.eks_cluster_id
7596
kubernetes_version = var.kubernetes_version
7697
kubernetes_labels = var.kubernetes_labels
7798
disk_size = var.disk_size

examples/complete/outputs.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ output "vpc_cidr" {
1313
description = "VPC ID"
1414
}
1515

16+
output "eks_cluster_security_group_id" {
17+
description = "ID of the EKS cluster Security Group"
18+
value = module.eks_cluster.security_group_id
19+
}
20+
21+
output "eks_cluster_security_group_arn" {
22+
description = "ARN of the EKS cluster Security Group"
23+
value = module.eks_cluster.security_group_arn
24+
}
25+
26+
output "eks_cluster_security_group_name" {
27+
description = "Name of the EKS cluster Security Group"
28+
value = module.eks_cluster.security_group_name
29+
}
30+
1631
output "eks_cluster_id" {
1732
description = "The name of the cluster"
1833
value = module.eks_cluster.eks_cluster_id
@@ -38,6 +53,11 @@ output "eks_cluster_identity_oidc_issuer" {
3853
value = module.eks_cluster.eks_cluster_identity_oidc_issuer
3954
}
4055

56+
output "eks_cluster_managed_security_group_id" {
57+
description = "Security Group ID that was created by EKS for the cluster. EKS creates a Security Group and applies it to ENI that is attached to EKS Control Plane master nodes and to any managed workloads"
58+
value = module.eks_cluster.eks_cluster_managed_security_group_id
59+
}
60+
4161
output "eks_node_group_role_arn" {
4262
description = "ARN of the worker nodes IAM role"
4363
value = module.eks_node_group.eks_node_group_role_arn

0 commit comments

Comments
 (0)