-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
595 additions
and
135 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -29,4 +29,7 @@ override.tf.json | |
# example: *tfplan* | ||
|
||
# ides | ||
.idea | ||
.idea | ||
|
||
# Generated | ||
*.pem |
This file contains 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 |
---|---|---|
@@ -1,43 +1,43 @@ | ||
data "template_cloudinit_config" "this" { | ||
count = var.server_count | ||
|
||
gzip = true | ||
base64_encode = true | ||
|
||
# Main cloud-init config file | ||
part { | ||
filename = "cloud-config.yaml" | ||
content_type = "text/cloud-config" | ||
content = templatefile("${path.module}/files/cloud-config.yaml", { | ||
ssh_authorized_keys = var.ssh_authorized_keys | ||
}) | ||
} | ||
|
||
part { | ||
filename = "00_cfg.sh" | ||
content_type = "text/x-shellscript" | ||
content = templatefile("${path.module}/files/server.sh", { | ||
server_index = count.index | ||
server_lb = module.cp_lb.dns | ||
|
||
args = { | ||
"token" = random_password.token.result | ||
} | ||
|
||
list_args = { | ||
"tls-san" = [module.cp_lb.dns] | ||
} | ||
|
||
# User defined config | ||
config = var.rke2_config | ||
}) | ||
} | ||
|
||
part { | ||
filename = "01_rke2.sh" | ||
content_type = "text/x-shellscript" | ||
content = templatefile("${path.module}/common/rke2.sh", { | ||
type = "server" | ||
}) | ||
} | ||
} | ||
//data "template_cloudinit_config" "this" { | ||
// count = var.server_count | ||
// | ||
// gzip = true | ||
// base64_encode = true | ||
// | ||
// # Main cloud-init config file | ||
// part { | ||
// filename = "cloud-config.yaml" | ||
// content_type = "text/cloud-config" | ||
// content = templatefile("${path.module}/files/cloud-config.yaml", { | ||
// ssh_authorized_keys = var.ssh_authorized_keys | ||
// }) | ||
// } | ||
// | ||
// part { | ||
// filename = "00_cfg.sh" | ||
// content_type = "text/x-shellscript" | ||
// content = templatefile("${path.module}/files/server.sh", { | ||
// server_index = count.index | ||
// server_lb = module.cp_lb.dns | ||
// | ||
// args = { | ||
// "token" = random_password.token.result | ||
// } | ||
// | ||
// list_args = { | ||
// "tls-san" = [module.cp_lb.dns] | ||
// } | ||
// | ||
// # User defined config | ||
// config = var.rke2_config | ||
// }) | ||
// } | ||
// | ||
// part { | ||
// filename = "01_rke2.sh" | ||
// content_type = "text/x-shellscript" | ||
// content = templatefile("${path.module}/common/rke2.sh", { | ||
// type = "server" | ||
// }) | ||
// } | ||
//} |
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,16 +1,44 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
build_config() { | ||
if [ "$${DEBUG}" == 2 ]; then | ||
set -x | ||
fi | ||
|
||
# info logs the given argument at info log level. | ||
info() { | ||
echo "[INFO] " "$@" | ||
} | ||
|
||
# warn logs the given argument at warn log level. | ||
warn() { | ||
echo "[WARN] " "$@" >&2 | ||
} | ||
|
||
# fatal logs the given argument at fatal log level. | ||
fatal() { | ||
echo "[ERROR] " "$@" >&2 | ||
exit 1 | ||
} | ||
|
||
config() { | ||
mkdir -p "/etc/rancher/rke2" | ||
cat <<-EOF > "/etc/rancher/rke2/config.yaml" | ||
token: ${token} | ||
server: ${server} | ||
server: "${server}" | ||
token: "${token}" | ||
${config} | ||
EOF | ||
} | ||
|
||
start() { | ||
config | ||
|
||
systemctl enable "rke2-agent" | ||
systemctl daemon-reload | ||
systemctl start "rke2-agent" | ||
} | ||
|
||
{ | ||
build_config | ||
start | ||
} |
File renamed without changes.
This file contains 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,82 @@ | ||
# | ||
# Launch template | ||
# | ||
resource "aws_launch_template" "this" { | ||
name = "${var.name}-rke2-nodepool" | ||
image_id = var.ami | ||
instance_type = var.instance_type | ||
user_data = var.userdata | ||
vpc_security_group_ids = var.vpc_security_group_ids | ||
|
||
block_device_mappings { | ||
device_name = "/dev/sda1" | ||
ebs { | ||
volume_size = var.block_device_mappings.size | ||
encrypted = var.block_device_mappings.encrypted | ||
delete_on_termination = true | ||
} | ||
} | ||
|
||
dynamic "iam_instance_profile" { | ||
for_each = var.iam_instance_profile != "" ? [var.iam_instance_profile] : [] | ||
content { | ||
name = iam_instance_profile.value | ||
} | ||
} | ||
|
||
tags = var.tags | ||
} | ||
|
||
# | ||
# Autoscaling group | ||
# | ||
resource "aws_autoscaling_group" "this" { | ||
name = "${var.name}-rke2-nodepool" | ||
vpc_zone_identifier = var.subnets | ||
|
||
min_size = var.asg.min | ||
max_size = var.asg.max | ||
desired_capacity = var.asg.desired | ||
|
||
# Health check and target groups dependent on whether we're a server or not (identified via k3s_url) | ||
health_check_type = var.health_check_type | ||
target_group_arns = var.target_group_arns | ||
|
||
dynamic "launch_template" { | ||
for_each = var.spot ? [] : ["spot"] | ||
|
||
content { | ||
id = aws_launch_template.this.id | ||
version = "$Latest" | ||
} | ||
} | ||
|
||
dynamic "mixed_instances_policy" { | ||
for_each = var.spot ? ["spot"] : [] | ||
|
||
content { | ||
instances_distribution { | ||
on_demand_base_capacity = 0 | ||
on_demand_percentage_above_base_capacity = 0 | ||
} | ||
|
||
launch_template { | ||
launch_template_specification { | ||
launch_template_id = aws_launch_template.this.id | ||
launch_template_name = aws_launch_template.this.name | ||
version = "$Latest" | ||
} | ||
} | ||
} | ||
} | ||
|
||
dynamic "tag" { | ||
for_each = var.tags | ||
|
||
content { | ||
key = tag.key | ||
value = tag.value | ||
propagate_at_launch = true | ||
} | ||
} | ||
} |
Oops, something went wrong.