Skip to content

Commit ed4b41d

Browse files
author
Dawid Rogaczewski
committed
address feedback part 2
1 parent 03fc93a commit ed4b41d

File tree

28 files changed

+369
-182
lines changed

28 files changed

+369
-182
lines changed

examples/bottlerocket/main.tf

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ locals {
66
name = "bottlerocket-${random_string.suffix.result}"
77
}
88

9+
variable "region" {
10+
description = "AWS region where example will be created"
11+
type = string
12+
default = "eu-west-1"
13+
}
14+
15+
variable "cluster_version" {
16+
description = "EKS version"
17+
type = string
18+
default = "1.20"
19+
}
20+
921
################################################################################
1022
# Supporting Resources
1123
################################################################################
@@ -51,6 +63,7 @@ module "vpc" {
5163
################################################################################
5264
# EKS Module
5365
################################################################################
66+
5467
data "aws_eks_cluster" "cluster" {
5568
name = module.eks.cluster_id
5669
}
@@ -102,7 +115,7 @@ module "eks" {
102115
userdata_template_extra_args = {
103116
enable_admin_container = false
104117
enable_control_container = true
105-
aws_region = var.region
118+
aws_region = data.aws_region.current.name
106119
}
107120
# example of k8s/kubelet configuration via additional_userdata
108121
additional_userdata = <<EOT
@@ -130,6 +143,8 @@ resource "aws_iam_role_policy_attachment" "ssm" {
130143
# Supporting Resources
131144
################################################################################
132145

146+
data "aws_region" "current" {}
147+
133148
data "aws_ami" "bottlerocket_ami" {
134149
most_recent = true
135150
owners = ["amazon"]

examples/bottlerocket/variables.tf

-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
1-
variable "region" {
2-
description = "AWS region where example will be created"
3-
type = string
4-
default = "eu-west-1"
5-
}
6-
7-
variable "cluster_version" {
8-
description = "EKS version"
9-
type = string
10-
default = "1.20"
11-
}

examples/complete/main.tf

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ locals {
66
name = "complete-${random_string.suffix.result}"
77
}
88

9+
variable "region" {
10+
description = "AWS region where example will be created"
11+
type = string
12+
default = "eu-west-1"
13+
}
14+
15+
variable "cluster_version" {
16+
description = "EKS version"
17+
type = string
18+
default = "1.20"
19+
}
20+
921
################################################################################
1022
# Supporting Resources
1123
################################################################################
@@ -51,6 +63,7 @@ module "vpc" {
5163
################################################################################
5264
# EKS Module
5365
################################################################################
66+
5467
data "aws_eks_cluster" "cluster" {
5568
name = module.eks.cluster_id
5669
}

examples/complete/variables.tf

-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
1-
variable "region" {
2-
description = "AWS region where example will be created"
3-
type = string
4-
default = "eu-west-1"
5-
}
6-
7-
variable "cluster_version" {
8-
description = "EKS version"
9-
type = string
10-
default = "1.20"
11-
}

examples/fargate/main.tf

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ locals {
66
name = "fargate-${random_string.suffix.result}"
77
}
88

9+
variable "region" {
10+
description = "AWS region where example will be created"
11+
type = string
12+
default = "eu-west-1"
13+
}
14+
15+
variable "cluster_version" {
16+
description = "EKS version"
17+
type = string
18+
default = "1.20"
19+
}
20+
921
################################################################################
1022
# Supporting Resources
1123
################################################################################
@@ -51,6 +63,7 @@ module "vpc" {
5163
################################################################################
5264
# EKS Module
5365
################################################################################
66+
5467
data "aws_eks_cluster" "cluster" {
5568
name = module.eks.cluster_id
5669
}

examples/fargate/variables.tf

-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
1-
variable "region" {
2-
description = "AWS region where example will be created"
3-
type = string
4-
default = "eu-west-1"
5-
}
6-
7-
variable "cluster_version" {
8-
description = "EKS version"
9-
type = string
10-
default = "1.20"
11-
}

examples/instance_refresh/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Instance refresh example
22

3-
This is EKS example using instance refresh feature for worker groups.
3+
This is EKS example using [instance refresh](https://aws.amazon.com/blogs/compute/introducing-instance-refresh-for-ec2-auto-scaling/) feature for worker groups.
4+
5+
See [the official documentation](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-refresh.html) for more details.
46

57
## Usage
68

examples/instance_refresh/main.tf

+21-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ locals {
66
name = "instance_refresh-${random_string.suffix.result}"
77
}
88

9+
variable "region" {
10+
description = "AWS region where example will be created"
11+
type = string
12+
default = "eu-west-1"
13+
}
14+
15+
variable "cluster_version" {
16+
description = "EKS version"
17+
type = string
18+
default = "1.20"
19+
}
20+
921
################################################################################
1022
# Supporting Resources
1123
################################################################################
@@ -51,6 +63,7 @@ module "vpc" {
5163
################################################################################
5264
# EKS Module
5365
################################################################################
66+
5467
data "aws_eks_cluster" "cluster" {
5568
name = module.eks.cluster_id
5669
}
@@ -113,6 +126,8 @@ resource "aws_iam_policy" "aws_node_termination_handler" {
113126
policy = data.aws_iam_policy_document.aws_node_termination_handler.json
114127
}
115128

129+
data "aws_region" "current" {}
130+
116131
data "aws_iam_policy_document" "aws_node_termination_handler_events" {
117132
statement {
118133
effect = "Allow"
@@ -127,7 +142,7 @@ data "aws_iam_policy_document" "aws_node_termination_handler_events" {
127142
"sqs:SendMessage",
128143
]
129144
resources = [
130-
"arn:aws:sqs:${var.region}:${data.aws_caller_identity.current.account_id}:${local.name}",
145+
"arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.name}",
131146
]
132147
}
133148
}
@@ -192,7 +207,7 @@ module "aws_node_termination_handler_role" {
192207
role_name_prefix = local.name
193208
provider_url = replace(module.eks.cluster_oidc_issuer_url, "https://", "")
194209
role_policy_arns = [aws_iam_policy.aws_node_termination_handler.arn]
195-
oidc_fully_qualified_subjects = ["system:serviceaccount:${var.namespace}:${var.serviceaccount}"]
210+
oidc_fully_qualified_subjects = ["system:serviceaccount:kube-system:aws-node-termination-handler"]
196211
}
197212

198213
resource "helm_release" "aws_node_termination_handler" {
@@ -201,19 +216,19 @@ resource "helm_release" "aws_node_termination_handler" {
201216
]
202217

203218
name = "aws-node-termination-handler"
204-
namespace = var.namespace
219+
namespace = "kube-system"
205220
repository = "https://aws.github.io/eks-charts"
206221
chart = "aws-node-termination-handler"
207-
version = var.aws_node_termination_handler_chart_version
222+
version = "0.15.0"
208223
create_namespace = true
209224

210225
set {
211226
name = "awsRegion"
212-
value = var.region
227+
value = data.aws_region.current.name
213228
}
214229
set {
215230
name = "serviceAccount.name"
216-
value = var.serviceaccount
231+
value = "aws-node-termination-handler"
217232
}
218233
set {
219234
name = "serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
-29
Original file line numberDiff line numberDiff line change
@@ -1,29 +0,0 @@
1-
variable "region" {
2-
description = "AWS region where example will be created"
3-
type = string
4-
default = "eu-west-1"
5-
}
6-
7-
variable "cluster_version" {
8-
description = "EKS version"
9-
type = string
10-
default = "1.20"
11-
}
12-
13-
variable "aws_node_termination_handler_chart_version" {
14-
description = "Version of the aws-node-termination-handler Helm chart to install."
15-
type = string
16-
default = "0.15.0"
17-
}
18-
19-
variable "namespace" {
20-
description = "Namespace for the aws-node-termination-handler."
21-
type = string
22-
default = "kube-system"
23-
}
24-
25-
variable "serviceaccount" {
26-
description = "Serviceaccount for the aws-node-termination-handler."
27-
type = string
28-
default = "aws-node-termination-handler"
29-
}

examples/irsa/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This example shows how to create an IAM role to be used for a Kubernetes `ServiceAccount`. It will create a policy and role to be used by the [cluster-autoscaler](https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler) using the [public Helm chart](https://github.com/kubernetes/autoscaler/tree/master/charts/cluster-autoscaler).
44

5-
The AWS documentation for IRSA is here: https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html
5+
See [the official documentation](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html) for more details.
66

77
## Usage
88

examples/irsa/irsa.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
data "aws_caller_identity" "current" {}
22

3+
data "aws_region" "current" {}
4+
35
locals {
46
k8s_service_account_namespace = "kube-system"
57
k8s_service_account_name = "cluster-autoscaler-aws"
@@ -27,7 +29,7 @@ resource "helm_release" "cluster-autoscaler" {
2729

2830
set {
2931
name = "awsRegion"
30-
value = var.region
32+
value = data.aws_region.current.name
3133
}
3234
set {
3335
name = "rbac.serviceAccount.name"

examples/irsa/main.tf

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
provider "aws" {
2-
region = var.region
2+
33
}
44

55
locals {
66
name = "irsa-${random_string.suffix.result}"
77
}
88

9+
variable "region" {
10+
description = "AWS region where example will be created"
11+
type = string
12+
default = "eu-west-1"
13+
}
14+
15+
variable "cluster_version" {
16+
description = "EKS version"
17+
type = string
18+
default = "1.20"
19+
}
20+
921
################################################################################
1022
# Supporting Resources
1123
################################################################################

examples/irsa/variables.tf

-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
1-
variable "region" {
2-
description = "AWS region where example will be created"
3-
type = string
4-
default = "eu-west-1"
5-
}
6-
7-
variable "cluster_version" {
8-
description = "EKS version"
9-
type = string
10-
default = "1.20"
11-
}

examples/launch_templates/README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Launch templates example
2+
3+
This is EKS example using workers launch template with worker groups feature.
4+
5+
See [the official documentation](https://docs.aws.amazon.com/eks/latest/userguide/worker.html) for more details.
6+
7+
## Usage
8+
9+
To run this example you need to execute:
10+
11+
```bash
12+
$ terraform init
13+
$ terraform plan
14+
$ terraform apply
15+
```
16+
17+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
18+
19+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
20+
## Requirements
21+
22+
| Name | Version |
23+
|------|---------|
24+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.22.0 |
26+
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 1.11 |
27+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |
28+
29+
## Providers
30+
31+
| Name | Version |
32+
|------|---------|
33+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.22.0 |
34+
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.1 |
35+
36+
## Modules
37+
38+
| Name | Source | Version |
39+
|------|--------|---------|
40+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
41+
42+
## Resources
43+
44+
| Name | Type |
45+
|------|------|
46+
| [random_string.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
47+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
48+
49+
## Inputs
50+
51+
No inputs.
52+
53+
## Outputs
54+
55+
| Name | Description |
56+
|------|-------------|
57+
| <a name="output_cluster_name"></a> [cluster\_name](#output\_cluster\_name) | Name of EKS Cluster used in tags for subnets |
58+
| <a name="output_region"></a> [region](#output\_region) | AWS region |
59+
| <a name="output_vpc"></a> [vpc](#output\_vpc) | Complete output of VPC module |
60+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

0 commit comments

Comments
 (0)