From 1ff457f218554681fd24855f75b7c99555d4bfc5 Mon Sep 17 00:00:00 2001 From: Teodor Linkin Date: Thu, 4 Jul 2019 11:08:46 +0300 Subject: [PATCH 1/8] update variable min/max to single variable --- modules/nomad-cluster/main.tf | 6 +++--- modules/nomad-cluster/variables.tf | 16 +++------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/modules/nomad-cluster/main.tf b/modules/nomad-cluster/main.tf index e46194c..5fdbaf4 100644 --- a/modules/nomad-cluster/main.tf +++ b/modules/nomad-cluster/main.tf @@ -17,9 +17,9 @@ resource "aws_autoscaling_group" "autoscaling_group" { availability_zones = var.availability_zones vpc_zone_identifier = var.subnet_ids - min_size = var.min_size - max_size = var.max_size - desired_capacity = var.desired_capacity + min_size = var.cluster_size + max_size = var.cluster_size + desired_capacity = var.cluster_size termination_policies = [var.termination_policies] health_check_type = var.health_check_type diff --git a/modules/nomad-cluster/variables.tf b/modules/nomad-cluster/variables.tf index b0293a8..752d50f 100644 --- a/modules/nomad-cluster/variables.tf +++ b/modules/nomad-cluster/variables.tf @@ -33,20 +33,10 @@ variable "user_data" { type = string } -variable "min_size" { - description = "The minimum number of nodes to have in the cluster. If you're using this to run Nomad servers, we strongly recommend setting this to 3 or 5." +variable "cluster_size" { + description = "The number of nodes to have in the Nomad cluster. We strongly recommended that you use either 3 or 5." type = number -} - -variable "max_size" { - description = "The maximum number of nodes to have in the cluster. If you're using this to run Nomad servers, we strongly recommend setting this to 3 or 5." - type = number -} - -variable "desired_capacity" { - description = "The desired number of nodes to have in the cluster. If you're using this to run Nomad servers, we strongly recommend setting this to 3 or 5." - type = number -} + default = 3 # --------------------------------------------------------------------------------------------------------------------- # OPTIONAL PARAMETERS From 1ced9988fbed83ccc484f04767178a8c5ce78082 Mon Sep 17 00:00:00 2001 From: Teodor Linkin Date: Thu, 4 Jul 2019 15:43:50 +0300 Subject: [PATCH 2/8] update the example for sep cluster --- examples/nomad-consul-separate-cluster/main.tf | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/nomad-consul-separate-cluster/main.tf b/examples/nomad-consul-separate-cluster/main.tf index c29c23f..7963abc 100644 --- a/examples/nomad-consul-separate-cluster/main.tf +++ b/examples/nomad-consul-separate-cluster/main.tf @@ -67,13 +67,9 @@ module "nomad_servers" { source = "../../modules/nomad-cluster" cluster_name = "${var.nomad_cluster_name}-server" + cluster_size = var.num_nomad_servers instance_type = "t2.micro" - # You should typically use a fixed size of 3 or 5 for your Nomad server cluster - min_size = var.num_nomad_servers - max_size = var.num_nomad_servers - desired_capacity = var.num_nomad_servers - ami_id = var.ami_id == null ? data.aws_ami.nomad_consul.image_id : var.ami_id user_data = data.template_file.user_data_nomad_server.rendered From e33f916008db8c5ef2afbe6b9e054f963bdd1b35 Mon Sep 17 00:00:00 2001 From: Teodor Linkin Date: Thu, 4 Jul 2019 15:46:05 +0300 Subject: [PATCH 3/8] add support for spot price --- modules/nomad-cluster/main.tf | 1 + modules/nomad-cluster/variables.tf | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/modules/nomad-cluster/main.tf b/modules/nomad-cluster/main.tf index 5fdbaf4..347f426 100644 --- a/modules/nomad-cluster/main.tf +++ b/modules/nomad-cluster/main.tf @@ -58,6 +58,7 @@ resource "aws_launch_configuration" "launch_configuration" { image_id = var.ami_id instance_type = var.instance_type user_data = var.user_data + spot_price = var.spot_price iam_instance_profile = aws_iam_instance_profile.instance_profile.name key_name = var.ssh_key_name diff --git a/modules/nomad-cluster/variables.tf b/modules/nomad-cluster/variables.tf index 752d50f..bb8c0b5 100644 --- a/modules/nomad-cluster/variables.tf +++ b/modules/nomad-cluster/variables.tf @@ -97,6 +97,12 @@ variable "associate_public_ip_address" { default = false } +variable "spot_price" { + description = "The maximum hourly price to pay for EC2 Spot Instances." + type = number + default = null +} + variable "tenancy" { description = "The tenancy of the instance. Must be one of: default or dedicated." type = string From ce32fa843f172165ae1279f0ffe4d3b292d89ad2 Mon Sep 17 00:00:00 2001 From: Teodor Linkin Date: Thu, 4 Jul 2019 15:58:32 +0300 Subject: [PATCH 4/8] typo --- modules/nomad-cluster/variables.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/nomad-cluster/variables.tf b/modules/nomad-cluster/variables.tf index bb8c0b5..66b9a2f 100644 --- a/modules/nomad-cluster/variables.tf +++ b/modules/nomad-cluster/variables.tf @@ -37,6 +37,7 @@ variable "cluster_size" { description = "The number of nodes to have in the Nomad cluster. We strongly recommended that you use either 3 or 5." type = number default = 3 +} # --------------------------------------------------------------------------------------------------------------------- # OPTIONAL PARAMETERS From b421e81f83d9b09d485c236d3d9f4f31cb5efacf Mon Sep 17 00:00:00 2001 From: Teodor Linkin Date: Sat, 6 Jul 2019 10:28:38 +0300 Subject: [PATCH 5/8] update root example --- main.tf | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 5b21e38..834a73e 100644 --- a/main.tf +++ b/main.tf @@ -135,19 +135,13 @@ module "clients" { source = "./modules/nomad-cluster" cluster_name = "${var.cluster_name}-client" + cluster_size = var.num_servers instance_type = var.instance_type # Give the clients a different tag so they don't try to join the server cluster cluster_tag_key = "nomad-clients" cluster_tag_value = var.cluster_name - # To keep the example simple, we are using a fixed-size cluster. In real-world usage, you could use auto scaling - # policies to dynamically resize the cluster in response to load. - min_size = var.num_clients - - max_size = var.num_clients - desired_capacity = var.num_clients - ami_id = var.ami_id == null ? data.aws_ami.nomad_consul.image_id : var.ami_id user_data = data.template_file.user_data_client.rendered From 6b4757449c0f391084587e0043f3809c6be019a6 Mon Sep 17 00:00:00 2001 From: Teodor Linkin Date: Thu, 11 Jul 2019 07:56:13 +0300 Subject: [PATCH 6/8] fix number of clients --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 834a73e..d8ed87f 100644 --- a/main.tf +++ b/main.tf @@ -135,7 +135,7 @@ module "clients" { source = "./modules/nomad-cluster" cluster_name = "${var.cluster_name}-client" - cluster_size = var.num_servers + cluster_size = var.num_clients instance_type = var.instance_type # Give the clients a different tag so they don't try to join the server cluster From aed2aa536de6546110d7f4f2ed1d5402a8c5a2ed Mon Sep 17 00:00:00 2001 From: Teodor Linkin Date: Fri, 12 Jul 2019 00:07:08 +0300 Subject: [PATCH 7/8] fix error in other example --- examples/nomad-consul-separate-cluster/main.tf | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/examples/nomad-consul-separate-cluster/main.tf b/examples/nomad-consul-separate-cluster/main.tf index 7963abc..0193180 100644 --- a/examples/nomad-consul-separate-cluster/main.tf +++ b/examples/nomad-consul-separate-cluster/main.tf @@ -165,18 +165,13 @@ module "nomad_clients" { source = "../../modules/nomad-cluster" cluster_name = "${var.nomad_cluster_name}-client" + cluster_size = var.num_clients instance_type = "t2.micro" # Give the clients a different tag so they don't try to join the server cluster cluster_tag_key = "nomad-clients" cluster_tag_value = var.nomad_cluster_name - # To keep the example simple, we are using a fixed-size cluster. In real-world usage, you could use auto scaling - # policies to dynamically resize the cluster in response to load. - - min_size = var.num_nomad_clients - max_size = var.num_nomad_clients - desired_capacity = var.num_nomad_clients ami_id = var.ami_id == null ? data.aws_ami.nomad_consul.image_id : var.ami_id user_data = data.template_file.user_data_nomad_client.rendered vpc_id = data.aws_vpc.default.id From 70dfe92cc3fb849b9fd539581af81c5e802e78b9 Mon Sep 17 00:00:00 2001 From: Teodor Linkin Date: Fri, 12 Jul 2019 16:50:56 +0300 Subject: [PATCH 8/8] change tenancy to support spot pricing --- modules/nomad-cluster/variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/nomad-cluster/variables.tf b/modules/nomad-cluster/variables.tf index 66b9a2f..af2f20f 100644 --- a/modules/nomad-cluster/variables.tf +++ b/modules/nomad-cluster/variables.tf @@ -105,9 +105,9 @@ variable "spot_price" { } variable "tenancy" { - description = "The tenancy of the instance. Must be one of: default or dedicated." + description = "The tenancy of the instance. Must be one of: null, default or dedicated. For EC2 Spot Instances only null or dedicated can be used." type = string - default = "default" + default = null } variable "root_volume_ebs_optimized" {