Skip to content

Commit

Permalink
Merge pull request #37 from dirtbag/master
Browse files Browse the repository at this point in the history
Updated to allow for using multiple block device mappings
  • Loading branch information
joshrwolf authored Apr 1, 2021
2 parents b27097c + c6ea38a commit 71146b5
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 20 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ Optional policies have the option of being created by default, but are specified
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| ami | Server pool ami | `string` | n/a | yes |
| block\_device\_mappings | Server pool block device mapping configuration | `map(string)` | <pre>{<br> "encrypted": false,<br> "size": 30<br>}</pre> | no || cluster\_name | Name of the rkegov cluster to create | `string` | n/a | yes |
| block\_device\_mappings | Server pool block device mapping configuration | `map(string)` | <pre>{<br> "encrypted": false,<br> "size": 30<br>}</pre> | no |
| cluster\_name | Name of the rkegov cluster to create | `string` | n/a | yes |
| controlplane\_allowed\_cidrs | Server pool security group allowed cidr ranges | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
| controlplane\_enable\_cross\_zone\_load\_balancing | Toggle between controlplane cross zone load balancing | `bool` | `true` | no |
| controlplane\_internal | Toggle between public or private control plane load balancer | `bool` | `true` | no |
| download | Toggle best effort download of rke2 dependencies (rke2 and aws cli), if disabled, dependencies are assumed to exist in $PATH | `bool` | `true` | no |
| enable\_ccm | Toggle enabling the cluster as aws aware, this will ensure the appropriate IAM policies are present | `bool` | `false` | no |
| extra\_block\_device\_mappings | Additional server pool block device mappings configuration | `list(map(string))` | `[]` | no |
| iam\_instance\_profile | Server pool IAM Instance Profile, created if left blank (default behavior) | `string` | `""` | no |
| iam\_permissions\_boundary | If provided, the IAM role created for the servers will be created with this permissions boundary attached. | `string` | `null` | no |
| extra\_security\_group\_ids | List of additional security group IDs | `list(string)` | `[]` | no |
Expand Down
17 changes: 9 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,15 @@ module "servers" {
source = "./modules/nodepool"
name = "${local.uname}-server"

vpc_id = var.vpc_id
subnets = var.subnets
ami = var.ami
instance_type = var.instance_type
block_device_mappings = var.block_device_mappings
vpc_security_group_ids = concat([aws_security_group.server.id, aws_security_group.cluster.id], var.extra_security_group_ids)
spot = var.spot
load_balancers = [module.cp_lb.name]
vpc_id = var.vpc_id
subnets = var.subnets
ami = var.ami
instance_type = var.instance_type
block_device_mappings = var.block_device_mappings
extra_block_device_mappings = var.extra_block_device_mappings
vpc_security_group_ids = concat([aws_security_group.server.id, aws_security_group.cluster.id], var.extra_security_group_ids)
spot = var.spot
load_balancers = [module.cp_lb.name]

# Overrideable variables
userdata = data.template_cloudinit_config.this.rendered
Expand Down
1 change: 1 addition & 0 deletions modules/agent-nodepool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
| cluster\_data | Required data relevant to joining an existing rke2 cluster, sourced from main rke2 module, do NOT modify | <pre>object({<br> name = string<br> server_url = string<br> cluster_sg = string<br> token = object({<br> bucket = string<br> bucket_arn = string<br> object = string<br> policy_document = string<br> })<br> })</pre> | n/a | yes |
| enable\_autoscaler | Toggle configure the nodepool for cluster autoscaler, this will ensure the appropriate IAM policies are present, you are still responsible for ensuring cluster autoscaler is installed | `bool` | `false` | no |
| enable\_ccm | Toggle enabling the cluster as aws aware, this will ensure the appropriate IAM policies are present | `bool` | `false` | no |
| extra\_block\_device\_mappings | Additional node pool block device mappings configuration | `list(map(string))` | `[]` | no |
| extra\_security\_group\_ids | List of additional security group IDs | `list(string)` | `[]` | no |
| iam\_instance\_profile | Node pool IAM Instance Profile, created if node specified | `string` | `""` | no |
| instance\_type | Node pool instance type | `string` | `"t3.medium"` | no |
Expand Down
21 changes: 11 additions & 10 deletions modules/agent-nodepool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,17 @@ module "nodepool" {
source = "../nodepool"
name = "${local.name}-agent"

vpc_id = var.vpc_id
subnets = var.subnets
ami = var.ami
instance_type = var.instance_type
block_device_mappings = var.block_device_mappings
vpc_security_group_ids = concat([var.cluster_data.cluster_sg], var.extra_security_group_ids)
userdata = data.template_cloudinit_config.init.rendered
iam_instance_profile = var.iam_instance_profile == "" ? module.iam[0].iam_instance_profile : var.iam_instance_profile
asg = var.asg
spot = var.spot
vpc_id = var.vpc_id
subnets = var.subnets
ami = var.ami
instance_type = var.instance_type
block_device_mappings = var.block_device_mappings
extra_block_device_mappings = var.extra_block_device_mappings
vpc_security_group_ids = concat([var.cluster_data.cluster_sg], var.extra_security_group_ids)
userdata = data.template_cloudinit_config.init.rendered
iam_instance_profile = var.iam_instance_profile == "" ? module.iam[0].iam_instance_profile : var.iam_instance_profile
asg = var.asg
spot = var.spot

tags = merge({
"Role" = "agent",
Expand Down
7 changes: 7 additions & 0 deletions modules/agent-nodepool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ variable "block_device_mappings" {
}
}

variable "extra_block_device_mappings" {
description = "Used to specify additional block device mapping configurations"
type = list(map(string))
default = [
]
}

variable "asg" {
description = "Node pool AutoScalingGroup scaling definition"
type = object({
Expand Down
15 changes: 15 additions & 0 deletions modules/nodepool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ resource "aws_launch_template" "this" {
}
}

dynamic "block_device_mappings" {
for_each = var.extra_block_device_mappings
content {
device_name = lookup(block_device_mappings.value, "device_name", "null")
ebs {
volume_type = lookup(block_device_mappings.value, "type", null)
volume_size = lookup(block_device_mappings.value, "size", null)
iops = lookup(block_device_mappings.value, "iops", null)
kms_key_id = lookup(block_device_mappings.value, "kms_key_id", null)
encrypted = lookup(block_device_mappings.value, "encrypted", null)
delete_on_termination = lookup(block_device_mappings.value, "delete_on_termination", null)
}
}
}

iam_instance_profile {
name = var.iam_instance_profile
}
Expand Down
6 changes: 6 additions & 0 deletions modules/nodepool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ variable "block_device_mappings" {
}
}

variable "extra_block_device_mappings" {
type = list(map(string))
default = [
]
}

variable "asg" {
type = object({
min = number
Expand Down
9 changes: 8 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ variable "block_device_mappings" {
}
}

variable "extra_block_device_mappings" {
description = "Used to specify additional block device mapping configurations"
type = list(map(string))
default = [
]
}

variable "servers" {
description = "Number of servers to create"
type = number
Expand Down Expand Up @@ -136,4 +143,4 @@ variable "enable_ccm" {
description = "Toggle enabling the cluster as aws aware, this will ensure the appropriate IAM policies are present"
type = bool
default = false
}
}

0 comments on commit 71146b5

Please sign in to comment.