Skip to content

Commit

Permalink
address feedback part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawid Rogaczewski committed Oct 12, 2021
1 parent 03fc93a commit ed4b41d
Show file tree
Hide file tree
Showing 28 changed files with 369 additions and 182 deletions.
17 changes: 16 additions & 1 deletion examples/bottlerocket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ locals {
name = "bottlerocket-${random_string.suffix.result}"
}

variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}

################################################################################
# Supporting Resources
################################################################################
Expand Down Expand Up @@ -51,6 +63,7 @@ module "vpc" {
################################################################################
# EKS Module
################################################################################

data "aws_eks_cluster" "cluster" {
name = module.eks.cluster_id
}
Expand Down Expand Up @@ -102,7 +115,7 @@ module "eks" {
userdata_template_extra_args = {
enable_admin_container = false
enable_control_container = true
aws_region = var.region
aws_region = data.aws_region.current.name
}
# example of k8s/kubelet configuration via additional_userdata
additional_userdata = <<EOT
Expand Down Expand Up @@ -130,6 +143,8 @@ resource "aws_iam_role_policy_attachment" "ssm" {
# Supporting Resources
################################################################################

data "aws_region" "current" {}

data "aws_ami" "bottlerocket_ami" {
most_recent = true
owners = ["amazon"]
Expand Down
11 changes: 0 additions & 11 deletions examples/bottlerocket/variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}
13 changes: 13 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ locals {
name = "complete-${random_string.suffix.result}"
}

variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}

################################################################################
# Supporting Resources
################################################################################
Expand Down Expand Up @@ -51,6 +63,7 @@ module "vpc" {
################################################################################
# EKS Module
################################################################################

data "aws_eks_cluster" "cluster" {
name = module.eks.cluster_id
}
Expand Down
11 changes: 0 additions & 11 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}
13 changes: 13 additions & 0 deletions examples/fargate/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ locals {
name = "fargate-${random_string.suffix.result}"
}

variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}

################################################################################
# Supporting Resources
################################################################################
Expand Down Expand Up @@ -51,6 +63,7 @@ module "vpc" {
################################################################################
# EKS Module
################################################################################

data "aws_eks_cluster" "cluster" {
name = module.eks.cluster_id
}
Expand Down
11 changes: 0 additions & 11 deletions examples/fargate/variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}
4 changes: 3 additions & 1 deletion examples/instance_refresh/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Instance refresh example

This is EKS example using instance refresh feature for worker groups.
This is EKS example using [instance refresh](https://aws.amazon.com/blogs/compute/introducing-instance-refresh-for-ec2-auto-scaling/) feature for worker groups.

See [the official documentation](https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-refresh.html) for more details.

## Usage

Expand Down
27 changes: 21 additions & 6 deletions examples/instance_refresh/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ locals {
name = "instance_refresh-${random_string.suffix.result}"
}

variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}

################################################################################
# Supporting Resources
################################################################################
Expand Down Expand Up @@ -51,6 +63,7 @@ module "vpc" {
################################################################################
# EKS Module
################################################################################

data "aws_eks_cluster" "cluster" {
name = module.eks.cluster_id
}
Expand Down Expand Up @@ -113,6 +126,8 @@ resource "aws_iam_policy" "aws_node_termination_handler" {
policy = data.aws_iam_policy_document.aws_node_termination_handler.json
}

data "aws_region" "current" {}

data "aws_iam_policy_document" "aws_node_termination_handler_events" {
statement {
effect = "Allow"
Expand All @@ -127,7 +142,7 @@ data "aws_iam_policy_document" "aws_node_termination_handler_events" {
"sqs:SendMessage",
]
resources = [
"arn:aws:sqs:${var.region}:${data.aws_caller_identity.current.account_id}:${local.name}",
"arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.name}",
]
}
}
Expand Down Expand Up @@ -192,7 +207,7 @@ module "aws_node_termination_handler_role" {
role_name_prefix = local.name
provider_url = replace(module.eks.cluster_oidc_issuer_url, "https://", "")
role_policy_arns = [aws_iam_policy.aws_node_termination_handler.arn]
oidc_fully_qualified_subjects = ["system:serviceaccount:${var.namespace}:${var.serviceaccount}"]
oidc_fully_qualified_subjects = ["system:serviceaccount:kube-system:aws-node-termination-handler"]
}

resource "helm_release" "aws_node_termination_handler" {
Expand All @@ -201,19 +216,19 @@ resource "helm_release" "aws_node_termination_handler" {
]

name = "aws-node-termination-handler"
namespace = var.namespace
namespace = "kube-system"
repository = "https://aws.github.io/eks-charts"
chart = "aws-node-termination-handler"
version = var.aws_node_termination_handler_chart_version
version = "0.15.0"
create_namespace = true

set {
name = "awsRegion"
value = var.region
value = data.aws_region.current.name
}
set {
name = "serviceAccount.name"
value = var.serviceaccount
value = "aws-node-termination-handler"
}
set {
name = "serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
Expand Down
29 changes: 0 additions & 29 deletions examples/instance_refresh/variables.tf
Original file line number Diff line number Diff line change
@@ -1,29 +0,0 @@
variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}

variable "aws_node_termination_handler_chart_version" {
description = "Version of the aws-node-termination-handler Helm chart to install."
type = string
default = "0.15.0"
}

variable "namespace" {
description = "Namespace for the aws-node-termination-handler."
type = string
default = "kube-system"
}

variable "serviceaccount" {
description = "Serviceaccount for the aws-node-termination-handler."
type = string
default = "aws-node-termination-handler"
}
2 changes: 1 addition & 1 deletion examples/irsa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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).

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

## Usage

Expand Down
4 changes: 3 additions & 1 deletion examples/irsa/irsa.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
data "aws_caller_identity" "current" {}

data "aws_region" "current" {}

locals {
k8s_service_account_namespace = "kube-system"
k8s_service_account_name = "cluster-autoscaler-aws"
Expand Down Expand Up @@ -27,7 +29,7 @@ resource "helm_release" "cluster-autoscaler" {

set {
name = "awsRegion"
value = var.region
value = data.aws_region.current.name
}
set {
name = "rbac.serviceAccount.name"
Expand Down
14 changes: 13 additions & 1 deletion examples/irsa/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
provider "aws" {
region = var.region

}

locals {
name = "irsa-${random_string.suffix.result}"
}

variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}

################################################################################
# Supporting Resources
################################################################################
Expand Down
11 changes: 0 additions & 11 deletions examples/irsa/variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
variable "region" {
description = "AWS region where example will be created"
type = string
default = "eu-west-1"
}

variable "cluster_version" {
description = "EKS version"
type = string
default = "1.20"
}
60 changes: 60 additions & 0 deletions examples/launch_templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Launch templates example

This is EKS example using workers launch template with worker groups feature.

See [the official documentation](https://docs.aws.amazon.com/eks/latest/userguide/worker.html) for more details.

## Usage

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.22.0 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 1.11 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.22.0 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.1 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |

## Resources

| Name | Type |
|------|------|
| [random_string.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |

## Inputs

No inputs.

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_cluster_name"></a> [cluster\_name](#output\_cluster\_name) | Name of EKS Cluster used in tags for subnets |
| <a name="output_region"></a> [region](#output\_region) | AWS region |
| <a name="output_vpc"></a> [vpc](#output\_vpc) | Complete output of VPC module |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Loading

0 comments on commit ed4b41d

Please # to comment.