2019-10-31 21:06:54 +00:00
|
|
|
terraform {
|
|
|
|
backend "local" {
|
|
|
|
path = "pool.tfstate"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
|
|
|
name = var.name
|
2019-11-27 18:30:56 +00:00
|
|
|
k3s_cluster_secret = var.k3s_cluster_secret
|
2019-10-31 21:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
provider "aws" {
|
2019-11-15 11:14:28 +00:00
|
|
|
region = "us-east-2"
|
2019-10-31 21:06:54 +00:00
|
|
|
profile = "rancher-eng"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "k3s" {
|
|
|
|
name = "${local.name}-pool"
|
|
|
|
vpc_id = data.aws_vpc.default.id
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
from_port = 22
|
|
|
|
to_port = 22
|
|
|
|
protocol = "TCP"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
protocol = "-1"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
protocol = "-1"
|
|
|
|
self = true
|
|
|
|
}
|
|
|
|
|
|
|
|
egress {
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
protocol = "-1"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module "k3s-pool-worker-asg" {
|
|
|
|
source = "terraform-aws-modules/autoscaling/aws"
|
|
|
|
version = "3.0.0"
|
|
|
|
name = "${local.name}-pool"
|
|
|
|
asg_name = "${local.name}-pool"
|
2019-11-04 16:09:54 +00:00
|
|
|
instance_type = var.agent_instance_type
|
2019-10-31 21:06:54 +00:00
|
|
|
image_id = data.aws_ami.ubuntu.id
|
|
|
|
user_data = base64encode(templatefile("${path.module}/files/pool_worker_userdata.tmpl", { k3s_url = data.terraform_remote_state.server.outputs.public_ip, k3s_cluster_secret = local.k3s_cluster_secret, extra_ssh_keys = var.extra_ssh_keys, install_k3s_version = var.k3s_version }))
|
|
|
|
ebs_optimized = true
|
|
|
|
|
2019-11-04 16:09:54 +00:00
|
|
|
default_cooldown = 10
|
|
|
|
health_check_grace_period = 30
|
|
|
|
wait_for_capacity_timeout = "60m"
|
|
|
|
|
|
|
|
desired_capacity = var.agent_node_count
|
2019-10-31 21:06:54 +00:00
|
|
|
health_check_type = "EC2"
|
2019-11-04 16:09:54 +00:00
|
|
|
max_size = var.agent_node_count
|
|
|
|
min_size = var.agent_node_count
|
2019-10-31 21:06:54 +00:00
|
|
|
vpc_zone_identifier = [data.aws_subnet.selected.id]
|
|
|
|
spot_price = "0.680"
|
|
|
|
|
|
|
|
security_groups = [
|
|
|
|
aws_security_group.k3s.id,
|
|
|
|
]
|
|
|
|
|
|
|
|
lc_name = "${local.name}-pool"
|
|
|
|
|
|
|
|
root_block_device = [
|
|
|
|
{
|
2019-11-15 11:14:28 +00:00
|
|
|
volume_size = "30"
|
2019-10-31 21:06:54 +00:00
|
|
|
volume_type = "gp2"
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|