-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Node groups submodule #650
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 38 commits into
terraform-aws-modules:master
from
dpiddock:node-groups
Jan 9, 2020
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
b84b346
WIP Move node_groups to a submodule
dpiddock ffcf54b
Split the old node_groups file up
dpiddock 384dbed
Start moving locals
dpiddock 07ad28e
Simplify IAM creation logic
dpiddock c880766
depends_on from the TF docs
dpiddock eea2ab4
Wire in the variables
dpiddock 058d26c
Call module from parent
dpiddock 283d50d
Allow to customize the role name. As per workers
dpiddock 11d9008
aws_auth ConfigMap for node_groups
dpiddock 7a8b60a
Get the managed_node_groups example to plan
dpiddock 55195bb
Get the basic example to plan too
dpiddock e8c60da
create_eks = false works
dpiddock f81984b
Update Changelog
dpiddock 55ab21f
Update README
dpiddock c3a27b3
Wire in node_groups_defaults
dpiddock ada2634
Remove node_groups from workers_defaults_defaults
dpiddock d9f795a
Synchronize random and node_group defaults
dpiddock 2e45ba7
Error: "name_prefix" cannot be longer than 32
dpiddock 2bd52e9
Update READMEs again
dpiddock fa598fd
Fix double destroy
dpiddock d628605
Remove duplicate iam_role in node_group
dpiddock 812daf3
Fix index fail if node group manually deleted
dpiddock 6560f21
Keep aws_auth template in top module
dpiddock 7c8aee7
Hack to have node_groups depend on aws_auth etc
dpiddock e36342e
Pull variables via the random_pet to cut logic
dpiddock 12c92e2
Pass all ForceNew variables through the pet
dpiddock 47c8635
Do a deep merge of NG labels and tags
dpiddock 4f64d9c
Update README.. again
dpiddock 78c9272
Additional managed node outputs #644
dpiddock 5272127
Remove unused local
dpiddock 34bd697
Use more for_each
dpiddock 7f0a2c6
Remove the change when create_eks = false
dpiddock 0d322da
Make documentation less confusing
dpiddock 0bab29e
node_group version user configurable
dpiddock 3c77ccf
Pass through raw output from aws_eks_node_groups
dpiddock 48f0c03
Merge workers defaults in the locals
dpiddock 59813e6
Merge branch 'master' into node-groups
max-rocket-internet c996076
Fix typo
dpiddock 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
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,55 @@ | ||
| # eks `node_groups` submodule | ||
|
|
||
| Helper submodule to create and manage resources related to `eks_node_groups`. | ||
|
|
||
| ## Assumptions | ||
| * Designed for use by the parent module and not directly by end users | ||
|
|
||
| ## Node Groups' IAM Role | ||
| The role ARN specified in `var.default_iam_role_arn` will be used by default. In a simple configuration this will be the worker role created by the parent module. | ||
|
|
||
| `iam_role_arn` must be specified in either `var.node_groups_defaults` or `var.node_groups` if the default parent IAM role is not being created for whatever reason, for example if `manage_worker_iam_resources` is set to false in the parent. | ||
|
|
||
| ## `node_groups` and `node_groups_defaults` keys | ||
| `node_groups_defaults` is a map that can take the below keys. Values will be used if not specified in individual node groups. | ||
|
|
||
| `node_groups` is a map of maps. Key of first level will be used as unique value for `for_each` resources and in the `aws_eks_node_group` name. Inner map can take the below values. | ||
dpiddockcmp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| | Name | Description | Type | If unset | | ||
| |------|-------------|:----:|:-----:| | ||
| | additional\_tags | Additional tags to apply to node group | map(string) | Only `var.tags` applied | | ||
dpiddockcmp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | ami\_release\_version | AMI version of workers | string | Provider default behavior | | ||
| | ami\_type | AMI Type. See Terraform or AWS docs | string | Provider default behavior | | ||
| | desired\_capacity | Desired number of workers | number | `var.workers_group_defaults[asg_desired_capacity]` | | ||
| | disk\_size | Workers' disk size | number | Provider default behavior | | ||
| | iam\_role\_arn | IAM role ARN for workers | string | `var.default_iam_role_arn` | | ||
| | instance\_type | Workers' instance type | string | `var.workers_group_defaults[instance_type]` | | ||
| | k8s\_labels | Kubernetes labels | map(string) | No labels applied | | ||
| | key\_name | Key name for workers. Set to empty string to disable remote access | string | `var.workers_group_defaults[key_name]` | | ||
| | max\_capacity | Max number of workers | number | `var.workers_group_defaults[asg_max_size]` | | ||
| | min\_capacity | Min number of workers | number | `var.workers_group_defaults[asg_min_size]` | | ||
| | source\_security\_group\_ids | Source security groups for remote access to workers | list(string) | If key\_name is specified: THE REMOTE ACCESS WILL BE OPENED TO THE WORLD | | ||
| | subnets | Subnets to contain workers | list(string) | `var.workers_group_defaults[subnets]` | | ||
| | version | Kubernetes version | string | Provider default behavior | | ||
|
|
||
| <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
| ## Inputs | ||
|
|
||
| | Name | Description | Type | Default | Required | | ||
| |------|-------------|:----:|:-----:|:-----:| | ||
| | cluster\_name | Name of parent cluster | string | n/a | yes | | ||
| | create\_eks | Controls if EKS resources should be created (it affects almost all resources) | bool | `"true"` | no | | ||
| | default\_iam\_role\_arn | ARN of the default IAM worker role to use if one is not specified in `var.node_groups` or `var.node_groups_defaults` | string | n/a | yes | | ||
| | node\_groups | Map of maps of `eks_node_groups` to create. See "`node_groups` and `node_groups_defaults` keys" section in README.md for more details | any | `{}` | no | | ||
| | node\_groups\_defaults | map of maps of node groups to create. See "`node_groups` and `node_groups_defaults` keys" section in README.md for more details | any | n/a | yes | | ||
| | tags | A map of tags to add to all resources | map(string) | n/a | yes | | ||
| | workers\_group\_defaults | Workers group defaults from parent | any | n/a | yes | | ||
|
|
||
| ## Outputs | ||
|
|
||
| | Name | Description | | ||
| |------|-------------| | ||
| | aws\_auth\_roles | Roles for use in aws-auth ConfigMap | | ||
| | node\_groups | Outputs from EKS node groups. Map of maps, keyed by `var.node_groups` keys. See `aws_eks_node_group` Terraform documentation for values | | ||
|
|
||
| <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
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,16 @@ | ||
| locals { | ||
| # Merge defaults and per-group values to make code cleaner | ||
| node_groups_expanded = { for k, v in var.node_groups : k => merge( | ||
| { | ||
| desired_capacity = var.workers_group_defaults["asg_desired_capacity"] | ||
| iam_role_arn = var.default_iam_role_arn | ||
| instance_type = var.workers_group_defaults["instance_type"] | ||
| key_name = var.workers_group_defaults["key_name"] | ||
| max_capacity = var.workers_group_defaults["asg_max_size"] | ||
| min_capacity = var.workers_group_defaults["asg_min_size"] | ||
| subnets = var.workers_group_defaults["subnets"] | ||
| }, | ||
| var.node_groups_defaults, | ||
| v, | ||
| ) if var.create_eks } | ||
| } |
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,49 @@ | ||
| resource "aws_eks_node_group" "workers" { | ||
| for_each = local.node_groups_expanded | ||
|
|
||
| node_group_name = join("-", [var.cluster_name, each.key, random_pet.node_groups[each.key].id]) | ||
|
|
||
| cluster_name = var.cluster_name | ||
| node_role_arn = each.value["iam_role_arn"] | ||
| subnet_ids = each.value["subnets"] | ||
|
|
||
| scaling_config { | ||
| desired_size = each.value["desired_capacity"] | ||
| max_size = each.value["max_capacity"] | ||
| min_size = each.value["min_capacity"] | ||
| } | ||
|
|
||
| ami_type = lookup(each.value, "ami_type", null) | ||
| disk_size = lookup(each.value, "disk_size", null) | ||
| instance_types = [each.value["instance_type"]] | ||
| release_version = lookup(each.value, "ami_release_version", null) | ||
|
|
||
| dynamic "remote_access" { | ||
| for_each = each.value["key_name"] != "" ? [{ | ||
| ec2_ssh_key = each.value["key_name"] | ||
| source_security_group_ids = lookup(each.value, "source_security_group_ids", []) | ||
| }] : [] | ||
|
|
||
| content { | ||
| ec2_ssh_key = remote_access.value["ec2_ssh_key"] | ||
| source_security_group_ids = remote_access.value["source_security_group_ids"] | ||
| } | ||
| } | ||
|
|
||
| version = lookup(each.value, "version", null) | ||
|
|
||
| labels = merge( | ||
barryib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lookup(var.node_groups_defaults, "k8s_labels", {}), | ||
| lookup(var.node_groups[each.key], "k8s_labels", {}) | ||
| ) | ||
|
|
||
| tags = merge( | ||
| var.tags, | ||
| lookup(var.node_groups_defaults, "additional_tags", {}), | ||
| lookup(var.node_groups[each.key], "additional_tags", {}), | ||
| ) | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| output "node_groups" { | ||
| description = "Outputs from EKS node groups. Map of maps, keyed by `var.node_groups` keys. See `aws_eks_node_group` Terraform documentation for values" | ||
| value = aws_eks_node_group.workers | ||
| } | ||
|
|
||
| output "aws_auth_roles" { | ||
| description = "Roles for use in aws-auth ConfigMap" | ||
| value = [ | ||
dpiddockcmp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for k, v in local.node_groups_expanded : { | ||
| worker_role_arn = lookup(v, "iam_role_arn", var.default_iam_role_arn) | ||
| platform = "linux" | ||
| } | ||
| ] | ||
| } | ||
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,21 @@ | ||
| resource "random_pet" "node_groups" { | ||
| for_each = local.node_groups_expanded | ||
|
|
||
| separator = "-" | ||
| length = 2 | ||
|
|
||
| keepers = { | ||
| ami_type = lookup(each.value, "ami_type", null) | ||
| disk_size = lookup(each.value, "disk_size", null) | ||
| instance_type = each.value["instance_type"] | ||
| iam_role_arn = each.value["iam_role_arn"] | ||
|
|
||
| key_name = each.value["key_name"] | ||
|
|
||
| source_security_group_ids = join("|", compact( | ||
| lookup(each.value, "source_security_group_ids", []) | ||
| )) | ||
| subnet_ids = join("|", each.value["subnets"]) | ||
| node_group_name = join("-", [var.cluster_name, each.key]) | ||
| } | ||
| } |
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,36 @@ | ||
| variable "create_eks" { | ||
| description = "Controls if EKS resources should be created (it affects almost all resources)" | ||
| type = bool | ||
| default = true | ||
| } | ||
|
|
||
| variable "cluster_name" { | ||
| description = "Name of parent cluster" | ||
| type = string | ||
| } | ||
|
|
||
| variable "default_iam_role_arn" { | ||
| description = "ARN of the default IAM worker role to use if one is not specified in `var.node_groups` or `var.node_groups_defaults`" | ||
| type = string | ||
| } | ||
|
|
||
| variable "workers_group_defaults" { | ||
| description = "Workers group defaults from parent" | ||
| type = any | ||
| } | ||
|
|
||
| variable "tags" { | ||
| description = "A map of tags to add to all resources" | ||
| type = map(string) | ||
| } | ||
|
|
||
| variable "node_groups_defaults" { | ||
| description = "map of maps of node groups to create. See \"`node_groups` and `node_groups_defaults` keys\" section in README.md for more details" | ||
| type = any | ||
| } | ||
|
|
||
| variable "node_groups" { | ||
| description = "Map of maps of `eks_node_groups` to create. See \"`node_groups` and `node_groups_defaults` keys\" section in README.md for more details" | ||
| type = any | ||
| default = {} | ||
| } |
Oops, something went wrong.
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.