Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

update variable min/max to single variable #49

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions examples/nomad-consul-separate-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -169,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
Expand Down
8 changes: 1 addition & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,13 @@ module "clients" {
source = "./modules/nomad-cluster"

cluster_name = "${var.cluster_name}-client"
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
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

Expand Down
7 changes: 4 additions & 3 deletions modules/nomad-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 11 additions & 14 deletions modules/nomad-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +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."
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."
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
}

# ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -107,10 +98,16 @@ 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."
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" {
Expand Down