Skip to content

Commit d6fa9f4

Browse files
Better examples, PR template changes, general tidy up (#375)
* adding 3 examples * removing old example * updating PR template * fix this typo * update after renaming default example * add missing launch_template_mixed stuff to aws_auth * fix 2 examples with public subnets * update changelog for new minor release
1 parent f083816 commit d6fa9f4

File tree

20 files changed

+270
-231
lines changed

20 files changed

+270
-231
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ Please explain the changes you made here and link to any relevant issues.
66

77
### Checklist
88

9-
- [ ] `terraform fmt` and `terraform validate` both work from the root and `examples/eks_test_fixture` directories (look in CI for an example)
10-
- [ ] Tests for the changes have been added and passing (for bug fixes/features)
11-
- [ ] Test results are pasted in this PR (in lieu of CI)
12-
- [ ] I've added my change to CHANGELOG.md
13-
- [ ] Any breaking changes are highlighted above
9+
- [ ] `terraform fmt` and `terraform validate` both work from the root and `examples/*` directories
10+
- [ ] CI tests are passing
11+
- [ ] I've added my change to CHANGELOG.md and highlighted any breaking changes
12+
- [ ] README.md has been updated after any changes to variables and outputs. See https://github.com/terraform-aws-modules/terraform-aws-eks/#doc-generation

.kitchen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
driver:
33
name: "terraform"
4-
root_module_directory: "examples/eks_test_fixture"
4+
root_module_directory: "examples/basic"
55

66
provisioner:
77
name: "terraform"

.travis.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,15 @@ script:
3434
- terraform init
3535
- terraform fmt -check=true
3636
- terraform validate -var "region=${AWS_REGION}" -var "vpc_id=vpc-123456" -var "subnets=[\"subnet-12345a\"]" -var "workers_ami_id=ami-123456" -var "cluster_ingress_cidrs=[]" -var "cluster_name=test_cluster"
37-
# - docker run --rm -v $(pwd):/app/ --workdir=/app/ -t wata727/tflint --error-with-issues
38-
- cd examples/eks_test_fixture
39-
- terraform init
40-
- terraform fmt -check=true
41-
- terraform validate
42-
- cd -
37+
- |
38+
for example in $(find examples -maxdepth 1 -mindepth 1 -type d); do
39+
cd $example
40+
terraform init
41+
terraform fmt -check=true
42+
terraform validate
43+
cd -
44+
done
4345
- terraform -v
44-
# - bundle exec kitchen test --destroy always
45-
# deploy:
46-
# provider: script
47-
# script: ci/deploy.sh
48-
# on:
49-
# branch: master
5046

5147
notifications:
5248
email:

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ project adheres to [Semantic Versioning](http://semver.org/).
1919

2020
# History
2121

22+
## [[v4.0.2](https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v4.0.0...v4.0.1)] - 2019-05-07]
23+
24+
### Changed
25+
26+
- Added 2 new examples, also tidy up basic example (by @max-rocket-internet)
27+
- Updates to travis, PR template (by @max-rocket-internet)
28+
- Fix typo in data.tf (by @max-rocket-internet)
29+
- Add missing launch template items in `aws_auth.tf` (by @max-rocket-internet)
30+
2231
## [[v4.0.1](https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v4.0.0...v4.0.1)] - 2019-05-07]
2332

2433
### Changed

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Read the [AWS docs on EKS to get connected to the k8s dashboard](https://docs.aw
1919

2020
## Usage example
2121

22-
A full example leveraging other community modules is contained in the [examples/eks_test_fixture directory](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/eks_test_fixture). Here's the gist of using it via the Terraform registry:
22+
A full example leveraging other community modules is contained in the [examples/basic directory](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/basic). Here's the gist of using it via the Terraform registry:
2323

2424
```hcl
2525
module "my-cluster" {
@@ -89,11 +89,6 @@ Report issues/questions/feature requests on in the [issues](https://github.com/t
8989

9090
Full contributing [guidelines are covered here](https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/CONTRIBUTING.md).
9191

92-
## IAM Permissions
93-
94-
Testing and using this repo requires a minimum set of IAM permissions. Test permissions
95-
are listed in the [eks_test_fixture README](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/eks_test_fixture/README.md).
96-
9792
## Change log
9893

9994
The [changelog](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/CHANGELOG.md) captures all important release notes.
@@ -133,11 +128,11 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
133128
| manage\_aws\_auth | Whether to apply the aws-auth configmap file. | string | `"true"` | no |
134129
| manage\_cluster\_iam\_resources | Whether to let the module manage cluster IAM resources. If set to false, cluster_iam_role_name must be specified. | string | `"true"` | no |
135130
| manage\_worker\_iam\_resources | Whether to let the module manage worker IAM resources. If set to false, iam_instance_profile_name must be specified for workers. | string | `"true"` | no |
136-
| map\_accounts | Additional AWS account numbers to add to the aws-auth configmap. See examples/eks_test_fixture/variables.tf for example format. | list | `[]` | no |
131+
| map\_accounts | Additional AWS account numbers to add to the aws-auth configmap. See examples/basic/variables.tf for example format. | list | `[]` | no |
137132
| map\_accounts\_count | The count of accounts in the map_accounts list. | string | `"0"` | no |
138-
| map\_roles | Additional IAM roles to add to the aws-auth configmap. See examples/eks_test_fixture/variables.tf for example format. | list | `[]` | no |
133+
| map\_roles | Additional IAM roles to add to the aws-auth configmap. See examples/basic/variables.tf for example format. | list | `[]` | no |
139134
| map\_roles\_count | The count of roles in the map_roles list. | string | `"0"` | no |
140-
| map\_users | Additional IAM users to add to the aws-auth configmap. See examples/eks_test_fixture/variables.tf for example format. | list | `[]` | no |
135+
| map\_users | Additional IAM users to add to the aws-auth configmap. See examples/basic/variables.tf for example format. | list | `[]` | no |
141136
| map\_users\_count | The count of roles in the map_users list. | string | `"0"` | no |
142137
| permissions\_boundary | If provided, all IAM roles will be created with this permissions boundary attached. | string | `""` | no |
143138
| subnets | A list of subnets to place the EKS cluster and workers within. | list | n/a | yes |

aws_auth.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ EOS
3333

3434
data "aws_caller_identity" "current" {}
3535

36+
data "template_file" "launch_template_mixed_worker_role_arns" {
37+
count = "${var.worker_group_launch_template_mixed_count}"
38+
template = "${file("${path.module}/templates/worker-role.tpl")}"
39+
40+
vars {
41+
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(coalescelist(aws_iam_instance_profile.workers_launch_template_mixed.*.role, data.aws_iam_instance_profile.custom_worker_group_launch_template_mixed_iam_instance_profile.*.role_name), count.index)}"
42+
}
43+
}
44+
3645
data "template_file" "launch_template_worker_role_arns" {
3746
count = "${var.worker_group_launch_template_count}"
3847
template = "${file("${path.module}/templates/worker-role.tpl")}"
@@ -55,7 +64,7 @@ data "template_file" "config_map_aws_auth" {
5564
template = "${file("${path.module}/templates/config-map-aws-auth.yaml.tpl")}"
5665

5766
vars {
58-
worker_role_arn = "${join("", distinct(concat(data.template_file.launch_template_worker_role_arns.*.rendered, data.template_file.worker_role_arns.*.rendered)))}"
67+
worker_role_arn = "${join("", distinct(concat(data.template_file.launch_template_worker_role_arns.*.rendered, data.template_file.worker_role_arns.*.rendered, data.template_file.launch_template_mixed_worker_role_arns.*.rendered)))}"
5968
map_users = "${join("", data.template_file.map_users.*.rendered)}"
6069
map_roles = "${join("", data.template_file.map_roles.*.rendered)}"
6170
map_accounts = "${join("", data.template_file.map_accounts.*.rendered)}"

data.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ data "template_file" "workers_launch_template_mixed" {
109109
cluster_name = "${aws_eks_cluster.this.name}"
110110
endpoint = "${aws_eks_cluster.this.endpoint}"
111111
cluster_auth_base64 = "${aws_eks_cluster.this.certificate_authority.0.data}"
112-
pre_userdata = "${lookup(var.worker_groups_launch_template[count.index], "pre_userdata", local.workers_group_defaults["pre_userdata"])}"
113-
additional_userdata = "${lookup(var.worker_groups_launch_template[count.index], "additional_userdata", local.workers_group_defaults["additional_userdata"])}"
114-
bootstrap_extra_args = "${lookup(var.worker_groups_launch_template[count.index], "bootstrap_extra_args", local.workers_group_defaults["bootstrap_extra_args"])}"
115-
kubelet_extra_args = "${lookup(var.worker_groups_launch_template[count.index], "kubelet_extra_args", local.workers_group_defaults["kubelet_extra_args"])}"
112+
pre_userdata = "${lookup(var.worker_groups_launch_template_mixed[count.index], "pre_userdata", local.workers_group_defaults["pre_userdata"])}"
113+
additional_userdata = "${lookup(var.worker_groups_launch_template_mixed[count.index], "additional_userdata", local.workers_group_defaults["additional_userdata"])}"
114+
bootstrap_extra_args = "${lookup(var.worker_groups_launch_template_mixed[count.index], "bootstrap_extra_args", local.workers_group_defaults["bootstrap_extra_args"])}"
115+
kubelet_extra_args = "${lookup(var.worker_groups_launch_template_mixed[count.index], "kubelet_extra_args", local.workers_group_defaults["kubelet_extra_args"])}"
116116
}
117117
}
118118

examples/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Examples
2+
3+
These serve a few purposes:
4+
5+
1. Shows developers how to use the module in a straightforward way as integrated with other terraform community supported modules.
6+
2. Serves as the test infrastructure for CI on the project.
7+
3. Provides a simple way to play with the Kubernetes cluster you create.

examples/eks_test_fixture/main.tf renamed to examples/basic/main.tf

Lines changed: 44 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,6 @@ data "aws_availability_zones" "available" {}
1515

1616
locals {
1717
cluster_name = "test-eks-${random_string.suffix.result}"
18-
19-
# the commented out worker group list below shows an example of how to define
20-
# multiple worker groups of differing configurations
21-
# worker_groups = [
22-
# {
23-
# asg_desired_capacity = 2
24-
# asg_max_size = 10
25-
# asg_min_size = 2
26-
# instance_type = "m4.xlarge"
27-
# name = "worker_group_a"
28-
# additional_userdata = "echo foo bar"
29-
# subnets = "${join(",", module.vpc.private_subnets)}"
30-
# },
31-
# {
32-
# asg_desired_capacity = 1
33-
# asg_max_size = 5
34-
# asg_min_size = 1
35-
# instance_type = "m4.2xlarge"
36-
# name = "worker_group_b"
37-
# additional_userdata = "echo foo bar"
38-
# subnets = "${join(",", module.vpc.private_subnets)}"
39-
# },
40-
# ]
41-
42-
43-
# the commented out worker group tags below shows an example of how to define
44-
# custom tags for the worker groups ASG
45-
# worker_group_tags = {
46-
# worker_group_a = [
47-
# {
48-
# key = "k8s.io/cluster-autoscaler/node-template/taint/nvidia.com/gpu"
49-
# value = "gpu:NoSchedule"
50-
# propagate_at_launch = true
51-
# },
52-
# ],
53-
# worker_group_b = [
54-
# {
55-
# key = "k8s.io/cluster-autoscaler/node-template/taint/nvidia.com/gpu"
56-
# value = "gpu:NoSchedule"
57-
# propagate_at_launch = true
58-
# },
59-
# ],
60-
# }
61-
62-
worker_groups = [
63-
{
64-
instance_type = "t2.small"
65-
additional_userdata = "echo foo bar"
66-
asg_desired_capacity = 2
67-
},
68-
]
69-
worker_groups_launch_template = [
70-
{
71-
instance_type = "t2.small"
72-
additional_userdata = "echo foo bar"
73-
additional_security_group_ids = "${aws_security_group.worker_group_mgmt_one.id},${aws_security_group.worker_group_mgmt_two.id}"
74-
asg_desired_capacity = 2
75-
},
76-
]
77-
tags = {
78-
Environment = "test"
79-
GithubRepo = "terraform-aws-eks"
80-
GithubOrg = "terraform-aws-modules"
81-
Workspace = "${terraform.workspace}"
82-
}
8318
}
8419

8520
resource "random_string" "suffix" {
@@ -89,7 +24,6 @@ resource "random_string" "suffix" {
8924

9025
resource "aws_security_group" "worker_group_mgmt_one" {
9126
name_prefix = "worker_group_mgmt_one"
92-
description = "SG to be applied to all *nix machines"
9327
vpc_id = "${module.vpc.vpc_id}"
9428

9529
ingress {
@@ -140,24 +74,57 @@ module "vpc" {
14074
version = "1.60.0"
14175
name = "test-vpc"
14276
cidr = "10.0.0.0/16"
143-
azs = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}", "${data.aws_availability_zones.available.names[2]}"]
77+
azs = ["${data.aws_availability_zones.available.names}"]
14478
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
14579
public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
14680
enable_nat_gateway = true
14781
single_nat_gateway = true
148-
tags = "${merge(local.tags, map("kubernetes.io/cluster/${local.cluster_name}", "shared"))}"
82+
83+
tags = {
84+
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
85+
}
86+
87+
public_subnet_tags = {
88+
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
89+
}
90+
91+
private_subnet_tags = {
92+
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
93+
"kubernetes.io/role/internal-elb" = "true"
94+
}
14995
}
15096

15197
module "eks" {
152-
source = "../.."
153-
cluster_name = "${local.cluster_name}"
154-
subnets = ["${module.vpc.private_subnets}"]
155-
tags = "${local.tags}"
156-
vpc_id = "${module.vpc.vpc_id}"
157-
worker_groups = "${local.worker_groups}"
158-
worker_groups_launch_template = "${local.worker_groups_launch_template}"
159-
worker_group_count = 1
160-
worker_group_launch_template_count = 1
98+
source = "../.."
99+
cluster_name = "${local.cluster_name}"
100+
subnets = ["${module.vpc.private_subnets}"]
101+
102+
tags = {
103+
Environment = "test"
104+
GithubRepo = "terraform-aws-eks"
105+
GithubOrg = "terraform-aws-modules"
106+
}
107+
108+
vpc_id = "${module.vpc.vpc_id}"
109+
worker_group_count = 2
110+
111+
worker_groups = [
112+
{
113+
name = "worker-group-1"
114+
instance_type = "t2.small"
115+
additional_userdata = "echo foo bar"
116+
asg_desired_capacity = 2
117+
additional_security_group_ids = "${aws_security_group.worker_group_mgmt_one.id}"
118+
},
119+
{
120+
name = "worker-group-2"
121+
instance_type = "t2.medium"
122+
additional_userdata = "echo foo bar"
123+
additional_security_group_ids = "${aws_security_group.worker_group_mgmt_two.id}"
124+
asg_desired_capacity = 1
125+
},
126+
]
127+
161128
worker_additional_security_group_ids = ["${aws_security_group.all_worker_mgmt.id}"]
162129
map_roles = "${var.map_roles}"
163130
map_roles_count = "${var.map_roles_count}"

examples/eks_test_fixture/outputs.tf renamed to examples/basic/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ output "kubectl_config" {
1414
}
1515

1616
output "config_map_aws_auth" {
17-
description = ""
17+
description = "A kubernetes configuration to authenticate to this EKS cluster."
1818
value = "${module.eks.config_map_aws_auth}"
1919
}
2020

0 commit comments

Comments
 (0)