Skip to content

Commit

Permalink
Merge pull request #1 from garutilorenzo/new_features
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
garutilorenzo authored Jul 25, 2023
2 parents 82ba253 + 9962639 commit 8ee51c3
Show file tree
Hide file tree
Showing 25 changed files with 1,784 additions and 800 deletions.
560 changes: 238 additions & 322 deletions README.md

Large diffs are not rendered by default.

71 changes: 20 additions & 51 deletions asg.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_autoscaling_group" "k8s_servers_asg" {
name = "k8s_servers"
name = "${var.common_prefix}-servers-asg-${var.environment}"
wait_for_capacity_timeout = "5m"
vpc_zone_identifier = var.vpc_private_subnets

Expand Down Expand Up @@ -28,7 +28,6 @@ resource "aws_autoscaling_group" "k8s_servers_asg" {
weighted_capacity = "1"
}
}

}
}

Expand All @@ -39,15 +38,18 @@ resource "aws_autoscaling_group" "k8s_servers_asg" {
health_check_type = "EC2"
force_delete = true

tag {
key = "provisioner"
value = "terraform"
propagate_at_launch = true
dynamic "tag" {
for_each = local.global_tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}

tag {
key = "environment"
value = var.environment
key = "Name"
value = "${var.common_prefix}-server-${var.environment}"
propagate_at_launch = true
}

Expand All @@ -57,24 +59,6 @@ resource "aws_autoscaling_group" "k8s_servers_asg" {
propagate_at_launch = true
}

tag {
key = "uuid"
value = var.uuid
propagate_at_launch = true
}

tag {
key = "scope"
value = "k8s-cluster"
propagate_at_launch = true
}

tag {
key = "Name"
value = "k8s-server-${var.environment}"
propagate_at_launch = true
}

tag {
key = "k8s.io/cluster-autoscaler/enabled"
value = ""
Expand All @@ -89,7 +73,7 @@ resource "aws_autoscaling_group" "k8s_servers_asg" {
}

resource "aws_autoscaling_group" "k8s_workers_asg" {
name = "k8s_workers"
name = "${var.common_prefix}-workers-asg-${var.environment}"
vpc_zone_identifier = var.vpc_private_subnets

lifecycle {
Expand Down Expand Up @@ -127,15 +111,18 @@ resource "aws_autoscaling_group" "k8s_workers_asg" {
health_check_type = "EC2"
force_delete = true

tag {
key = "provisioner"
value = "terraform"
propagate_at_launch = true
dynamic "tag" {
for_each = local.global_tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}

tag {
key = "environment"
value = var.environment
key = "Name"
value = "${var.common_prefix}-worker-${var.environment}"
propagate_at_launch = true
}

Expand All @@ -145,24 +132,6 @@ resource "aws_autoscaling_group" "k8s_workers_asg" {
propagate_at_launch = true
}

tag {
key = "uuid"
value = var.uuid
propagate_at_launch = true
}

tag {
key = "scope"
value = "k8s-cluster"
propagate_at_launch = true
}

tag {
key = "Name"
value = "k8s-worker-${var.environment}"
propagate_at_launch = true
}

tag {
key = "k8s.io/cluster-autoscaler/enabled"
value = ""
Expand Down
19 changes: 0 additions & 19 deletions bucket.tf

This file was deleted.

74 changes: 45 additions & 29 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ data "aws_iam_policy" "AmazonEC2ReadOnlyAccess" {
arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
}

data "aws_iam_policy" "AmazonSSMManagedInstanceCore" {
arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}

data "template_cloudinit_config" "k8s_server" {
gzip = true
base64_encode = true
Expand All @@ -14,25 +18,40 @@ data "template_cloudinit_config" "k8s_server" {

part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/install_k8s_utils.sh", { k8s_version = var.k8s_version, install_longhorn = var.install_longhorn, })
content = templatefile("${path.module}/files/install_k8s_utils.sh", {
k8s_version = var.k8s_version
})
}

part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/install_k8s.sh", {
is_k8s_server = true,
k8s_version = var.k8s_version,
k8s_dns_domain = var.k8s_dns_domain,
k8s_pod_subnet = var.k8s_pod_subnet,
k8s_service_subnet = var.k8s_service_subnet,
s3_bucket_name = var.s3_bucket_name,
kube_api_port = var.kube_api_port,
control_plane_url = aws_lb.k8s-server-lb.dns_name,
install_longhorn = var.install_longhorn,
longhorn_release = var.longhorn_release,
install_nginx_ingress = var.install_nginx_ingress,
extlb_listener_http_port = var.extlb_listener_http_port,
extlb_listener_https_port = var.extlb_listener_https_port,
is_k8s_server = true,
k8s_version = var.k8s_version,
k8s_dns_domain = var.k8s_dns_domain,
k8s_pod_subnet = var.k8s_pod_subnet,
k8s_service_subnet = var.k8s_service_subnet,
kubeadm_ca_secret_name = local.kubeadm_ca_secret_name,
kubeadm_token_secret_name = local.kubeadm_token_secret_name,
kubeadm_cert_secret_name = local.kubeadm_cert_secret_name,
kubeconfig_secret_name = local.kubeconfig_secret_name,
kube_api_port = var.kube_api_port,
control_plane_url = aws_lb.k8s_server_lb.dns_name,
install_nginx_ingress = var.install_nginx_ingress,
nginx_ingress_release = var.nginx_ingress_release,
efs_persistent_storage = var.efs_persistent_storage,
efs_csi_driver_release = var.efs_csi_driver_release,
efs_filesystem_id = var.efs_persistent_storage ? aws_efs_file_system.k8s_persistent_storage[0].id : "",
install_certmanager = var.install_certmanager,
certmanager_release = var.certmanager_release,
install_node_termination_handler = var.install_node_termination_handler,
node_termination_handler_release = var.node_termination_handler_release,
certmanager_email_address = var.certmanager_email_address,
extlb_listener_http_port = var.extlb_listener_http_port,
extlb_listener_https_port = var.extlb_listener_https_port,
default_secret_placeholder = var.default_secret_placeholder,
expose_kubeapi = var.expose_kubeapi,
k8s_tls_san_public = local.k8s_tls_san_public
})
}
}
Expand All @@ -49,16 +68,21 @@ data "template_cloudinit_config" "k8s_worker" {

part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/install_k8s_utils.sh", { k8s_version = var.k8s_version, install_longhorn = var.install_longhorn })
content = templatefile("${path.module}/files/install_k8s_utils.sh", {
k8s_version = var.k8s_version
})
}

part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/install_k8s_worker.sh", {
is_k8s_server = false,
s3_bucket_name = var.s3_bucket_name,
kube_api_port = var.kube_api_port,
control_plane_url = aws_lb.k8s-server-lb.dns_name,
is_k8s_server = false,
kubeadm_ca_secret_name = local.kubeadm_ca_secret_name,
kubeadm_token_secret_name = local.kubeadm_token_secret_name,
kubeadm_cert_secret_name = local.kubeadm_cert_secret_name,
kube_api_port = var.kube_api_port,
control_plane_url = aws_lb.k8s_server_lb.dns_name,
default_secret_placeholder = var.default_secret_placeholder,
})
}
}
Expand All @@ -70,11 +94,7 @@ data "aws_instances" "k8s_servers" {
]

instance_tags = {
k8s-instance-type = "k8s-server"
provisioner = "terraform"
environment = var.environment
uuid = var.uuid
scope = "k8s-cluster"
for tag, value in merge(local.global_tags, { k8s-instance-type = "k8s-server" }) : tag => value
}

instance_state_names = ["running"]
Expand All @@ -87,11 +107,7 @@ data "aws_instances" "k8s_workers" {
]

instance_tags = {
k8s-instance-type = "k8s-worker"
provisioner = "terraform"
environment = var.environment
uuid = var.uuid
scope = "k8s-cluster"
for tag, value in merge(local.global_tags, { k8s-instance-type = "k8s-worker" }) : tag => value
}

instance_state_names = ["running"]
Expand Down
Loading

0 comments on commit 8ee51c3

Please sign in to comment.