-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Support for EKS Managed Node Groups #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
max-rocket-internet
merged 24 commits into
terraform-aws-modules:master
from
wmorgan6796:master
Dec 4, 2019
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
3566e35
Finished first cut of managed node groups
e7a5ae4
Updated formatting and extra fields.
e229273
Updating Changelog and README
c6d0ffc
Merge branch 'master' into master
wmorgan6796 9325f31
Fixing formatting
e740b95
Merge remote-tracking branch 'origin/master'
2d36e7b
Fixing docs.
7e5191e
Updating required Version
0041063
Updating changelog
cea2ce6
Adding example for managed node groups
74585d6
Managed IAM Roles for Nodegroups now have correct policies. Tags can …
0b325c8
Fixing bug where people could set source_security_group_ids without s…
4efc7c8
Adding lifecycle create_before_destroy
646ce62
Adding random pet names for create_before_destroy
be22931
Updating per comments.
8236f7b
Updating required versions of terraform
b291fa8
Updating per comments.
4183054
Updating vars
d96c077
Updating minimum version for terraform
d11f590
Change worker_groups_managed_node_groups to node_groups
59916c2
Using for_each on the random_pet
a1bb244
Adding changes recommended by @eytanhanig
2b5b2c7
Merge branch 'master' into master
max-rocket-internet e703bc8
Update node_groups.tf
max-rocket-internet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| terraform { | ||
| required_version = ">= 0.12.6" | ||
| } | ||
|
|
||
| provider "aws" { | ||
| version = ">= 2.28.1" | ||
| region = var.region | ||
| } | ||
|
|
||
| provider "random" { | ||
| version = "~> 2.1" | ||
| } | ||
|
|
||
| provider "local" { | ||
| version = "~> 1.2" | ||
| } | ||
|
|
||
| provider "null" { | ||
| version = "~> 2.1" | ||
| } | ||
|
|
||
| provider "template" { | ||
| version = "~> 2.1" | ||
| } | ||
|
|
||
| data "aws_availability_zones" "available" { | ||
| } | ||
|
|
||
| locals { | ||
| cluster_name = "test-eks-${random_string.suffix.result}" | ||
| } | ||
|
|
||
| resource "random_string" "suffix" { | ||
| length = 8 | ||
| special = false | ||
| } | ||
|
|
||
| module "vpc" { | ||
| source = "terraform-aws-modules/vpc/aws" | ||
| version = "~> 2.6" | ||
|
|
||
| name = "test-vpc" | ||
| cidr = "172.16.0.0/16" | ||
| azs = data.aws_availability_zones.available.names | ||
| private_subnets = ["172.16.1.0/24", "172.16.2.0/24", "172.16.3.0/24"] | ||
| public_subnets = ["172.16.4.0/24", "172.16.5.0/24", "172.16.6.0/24"] | ||
| enable_nat_gateway = true | ||
| single_nat_gateway = true | ||
| enable_dns_hostnames = true | ||
|
|
||
| tags = { | ||
| "kubernetes.io/cluster/${local.cluster_name}" = "shared" | ||
| } | ||
|
|
||
| public_subnet_tags = { | ||
| "kubernetes.io/cluster/${local.cluster_name}" = "shared" | ||
| "kubernetes.io/role/elb" = "1" | ||
| } | ||
|
|
||
| private_subnet_tags = { | ||
| "kubernetes.io/cluster/${local.cluster_name}" = "shared" | ||
| "kubernetes.io/role/internal-elb" = "1" | ||
| } | ||
| } | ||
|
|
||
| module "eks" { | ||
| source = "../.." | ||
| cluster_name = local.cluster_name | ||
| subnets = module.vpc.private_subnets | ||
|
|
||
| tags = { | ||
| Environment = "test" | ||
| GithubRepo = "terraform-aws-eks" | ||
| GithubOrg = "terraform-aws-modules" | ||
| } | ||
|
|
||
| vpc_id = module.vpc.vpc_id | ||
|
|
||
| node_groups = [ | ||
| { | ||
| name = "example" | ||
|
|
||
| node_group_desired_capacity = 1 | ||
| node_group_max_capacity = 10 | ||
| node_group_min_capacity = 1 | ||
|
|
||
| instance_type = "m5.large" | ||
| node_group_k8s_labels = { | ||
| Environment = "test" | ||
| GithubRepo = "terraform-aws-eks" | ||
| GithubOrg = "terraform-aws-modules" | ||
| } | ||
| node_group_additional_tags = { | ||
| Environment = "test" | ||
| GithubRepo = "terraform-aws-eks" | ||
| GithubOrg = "terraform-aws-modules" | ||
| } | ||
| } | ||
| ] | ||
|
|
||
| map_roles = var.map_roles | ||
| map_users = var.map_users | ||
| map_accounts = var.map_accounts | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| output "cluster_endpoint" { | ||
| description = "Endpoint for EKS control plane." | ||
| value = module.eks.cluster_endpoint | ||
| } | ||
|
|
||
| output "cluster_security_group_id" { | ||
| description = "Security group ids attached to the cluster control plane." | ||
| value = module.eks.cluster_security_group_id | ||
| } | ||
|
|
||
| output "kubectl_config" { | ||
| description = "kubectl config as generated by the module." | ||
| value = module.eks.kubeconfig | ||
| } | ||
|
|
||
| output "config_map_aws_auth" { | ||
| description = "A kubernetes configuration to authenticate to this EKS cluster." | ||
| value = module.eks.config_map_aws_auth | ||
| } | ||
|
|
||
| output "region" { | ||
| description = "AWS region." | ||
| value = var.region | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| variable "region" { | ||
| default = "us-west-2" | ||
| } | ||
|
|
||
| variable "map_accounts" { | ||
| description = "Additional AWS account numbers to add to the aws-auth configmap." | ||
| type = list(string) | ||
|
|
||
| default = [ | ||
| "777777777777", | ||
| "888888888888", | ||
| ] | ||
| } | ||
|
|
||
| variable "map_roles" { | ||
| description = "Additional IAM roles to add to the aws-auth configmap." | ||
| type = list(object({ | ||
| rolearn = string | ||
| username = string | ||
| groups = list(string) | ||
| })) | ||
|
|
||
| default = [ | ||
| { | ||
| rolearn = "arn:aws:iam::66666666666:role/role1" | ||
| username = "role1" | ||
| groups = ["system:masters"] | ||
| }, | ||
| ] | ||
| } | ||
|
|
||
| variable "map_users" { | ||
| description = "Additional IAM users to add to the aws-auth configmap." | ||
| type = list(object({ | ||
| userarn = string | ||
| username = string | ||
| groups = list(string) | ||
| })) | ||
|
|
||
| default = [ | ||
| { | ||
| userarn = "arn:aws:iam::66666666666:user/user1" | ||
| username = "user1" | ||
| groups = ["system:masters"] | ||
| }, | ||
| { | ||
| userarn = "arn:aws:iam::66666666666:user/user2" | ||
| username = "user2" | ||
| groups = ["system:masters"] | ||
| }, | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| resource "aws_iam_role" "node_groups" { | ||
| count = local.worker_group_managed_node_group_count > 0 ? 1 : 0 | ||
| name = "${var.workers_role_name != "" ? var.workers_role_name : aws_eks_cluster.this.name}-managed-node-groups" | ||
| assume_role_policy = data.aws_iam_policy_document.workers_assume_role_policy.json | ||
| permissions_boundary = var.permissions_boundary | ||
| path = var.iam_path | ||
| force_detach_policies = true | ||
| tags = var.tags | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "node_groups_AmazonEKSWorkerNodePolicy" { | ||
| count = local.worker_group_managed_node_group_count > 0 ? 1 : 0 | ||
| policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy" | ||
| role = aws_iam_role.node_groups[0].name | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "node_groups_AmazonEKS_CNI_Policy" { | ||
| count = local.worker_group_managed_node_group_count > 0 ? 1 : 0 | ||
| policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" | ||
| role = aws_iam_role.node_groups[0].name | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "node_groups_AmazonEC2ContainerRegistryReadOnly" { | ||
| count = local.worker_group_managed_node_group_count > 0 ? 1 : 0 | ||
| policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" | ||
| role = aws_iam_role.node_groups[0].name | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "node_groups_additional_policies" { | ||
| for_each = toset(var.workers_additional_policies) | ||
|
|
||
| role = aws_iam_role.node_groups[0].name | ||
| policy_arn = each.key | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "node_groups_autoscaling" { | ||
| count = var.manage_worker_autoscaling_policy && var.attach_worker_autoscaling_policy && local.worker_group_managed_node_group_count > 0 ? 1 : 0 | ||
| policy_arn = aws_iam_policy.node_groups_autoscaling[0].arn | ||
| role = aws_iam_role.node_groups[0].name | ||
| } | ||
|
|
||
| resource "aws_iam_policy" "node_groups_autoscaling" { | ||
| count = var.manage_worker_autoscaling_policy && local.worker_group_managed_node_group_count > 0 ? 1 : 0 | ||
| name_prefix = "eks-worker-autoscaling-${aws_eks_cluster.this.name}" | ||
| description = "EKS worker node autoscaling policy for cluster ${aws_eks_cluster.this.name}" | ||
| policy = data.aws_iam_policy_document.worker_autoscaling.json | ||
| path = var.iam_path | ||
| } | ||
|
|
||
| resource "random_pet" "node_groups" { | ||
| for_each = local.node_groups | ||
|
|
||
| separator = "-" | ||
| length = 2 | ||
|
|
||
| keepers = { | ||
| instance_type = lookup(each.value, "instance_type", local.workers_group_defaults["instance_type"]) | ||
|
|
||
| ec2_ssh_key = lookup(each.value, "key_name", local.workers_group_defaults["key_name"]) | ||
|
|
||
| source_security_group_ids = join("-", compact( | ||
| lookup(each.value, "source_security_group_ids", local.workers_group_defaults["source_security_group_id"] | ||
| ))) | ||
|
|
||
| node_group_name = join("-", [var.cluster_name, each.value["name"]]) | ||
| } | ||
| } | ||
|
|
||
| resource "aws_eks_node_group" "workers" { | ||
| for_each = local.node_groups | ||
|
|
||
| node_group_name = join("-", [var.cluster_name, each.key, random_pet.node_groups[each.key].id]) | ||
|
|
||
| cluster_name = var.cluster_name | ||
| node_role_arn = lookup(each.value, "iam_role_arn", aws_iam_role.node_groups[0].arn) | ||
| subnet_ids = lookup(each.value, "subnets", local.workers_group_defaults["subnets"]) | ||
|
|
||
| scaling_config { | ||
| desired_size = lookup(each.value, "node_group_desired_capacity", local.workers_group_defaults["asg_desired_capacity"]) | ||
| max_size = lookup(each.value, "node_group_max_capacity", local.workers_group_defaults["asg_max_size"]) | ||
| min_size = lookup(each.value, "node_group_min_capacity", local.workers_group_defaults["asg_min_size"]) | ||
| } | ||
|
|
||
| ami_type = lookup(each.value, "ami_type", null) | ||
| disk_size = lookup(each.value, "root_volume_size", null) | ||
| instance_types = [lookup(each.value, "instance_type", null)] | ||
| labels = lookup(each.value, "node_group_k8s_labels", null) | ||
| release_version = lookup(each.value, "ami_release_version", null) | ||
|
|
||
| # This sometimes breaks idempotency as described in https://github.com/terraform-providers/terraform-provider-aws/issues/11063 | ||
| remote_access { | ||
| ec2_ssh_key = lookup(each.value, "key_name", "") != "" ? each.value["key_name"] : null | ||
| source_security_group_ids = lookup(each.value, "key_name", "") != "" ? lookup(each.value, "source_security_group_ids", []) : null | ||
| } | ||
|
|
||
| version = aws_eks_cluster.this.version | ||
|
|
||
| tags = lookup(each.value, "node_group_additional_tags", null) | ||
|
|
||
| lifecycle { | ||
| create_before_destroy = true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.