Skip to content
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
192 changes: 0 additions & 192 deletions aws/main.tf

This file was deleted.

44 changes: 0 additions & 44 deletions aws/scripts/talosconfiggen.sh

This file was deleted.

49 changes: 24 additions & 25 deletions aws/talos/main.tf
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ provider "aws" {

data "aws_ami" "talos"{
most_recent = true
name_regex = "^talos-v1.1.1-ap-south-1*"
name_regex = "^talos-v1.1.1*"
owners = ["540036508848"]

filter {
Expand All @@ -16,6 +16,7 @@ data "aws_ami" "talos"{

}


module "vpc" {
source = "terraform-aws-modules/vpc/aws"

Expand All @@ -28,13 +29,12 @@ module "vpc" {
}

resource "aws_internet_gateway" "ig" {
vpc_id = module.vpc.vpc_id
vpc_id = "${module.vpc.vpc_id}"
tags = {
Name = "${var.vpcname}-igw"
}
}


resource "aws_route" "igwroute" {
route_table_id = module.vpc.vpc_main_route_table_id
destination_cidr_block = "0.0.0.0/0"
Expand All @@ -56,15 +56,12 @@ module "security_group" {


ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = [ "k8s-apiserver" ]

rules = { "k8s-apiserver" : [ 6443 , 6443 , "tcp" , "Apiserver" ] , "all-all": [ -1, -1, "icmp", "All protocols" ]}

ingress_rules = ["http-80-tcp", "all-all"]

egress_rules = ["all-all"]

}


module "alb" {
source = "terraform-aws-modules/alb/aws"

Expand All @@ -74,10 +71,11 @@ module "alb" {

vpc_id = module.vpc.vpc_id

subnets = [ element(module.vpc.private_subnets, 0),element(module.vpc.private_subnets, 1) ]
subnets = [ "${element(module.vpc.private_subnets, 0)}","${element(module.vpc.private_subnets, 1)}" ]

}


resource "null_resource" "createtalosconfig" {
provisioner "local-exec" {

Expand Down Expand Up @@ -107,24 +105,19 @@ resource "aws_instance" talos_master_instance {
instance_type = var.instance_type
monitoring = var.nodemonitoringenabled
vpc_security_group_ids = [ module.security_group.security_group_id ]
subnet_id = element(module.vpc.private_subnets, 0)
subnet_id = "${element(module.vpc.private_subnets, 0)}"

user_data = data.local_file.controllerfile.content
associate_public_ip_address = true

depends_on = [ data.local_file.controllerfile ]

metadata_options {
http_tokens = "required"
}

tags = {
Name = "talosmaster"
}


}

resource "aws_instance" talos_worker_instance {

count = var.workercount
Expand All @@ -133,17 +126,13 @@ resource "aws_instance" talos_worker_instance {
instance_type = var.instance_type
monitoring = var.nodemonitoringenabled
vpc_security_group_ids = [ module.security_group.security_group_id ]
subnet_id = element(module.vpc.private_subnets, 0)
subnet_id = "${element(module.vpc.private_subnets, 0)}"

user_data = data.local_file.workerfile.content
associate_public_ip_address = false
associate_public_ip_address = true

depends_on = [ data.local_file.workerfile ]

metadata_options {
http_tokens = "required"
}

tags = {
Name = "talosworker"
}
Expand All @@ -161,12 +150,11 @@ resource "aws_lb_target_group" "talos-tg" {

}


resource "aws_lb_target_group_attachment" "registertarget" {

count = var.mastercount
target_group_arn = aws_lb_target_group.talos-tg.arn
target_id = element(split(",", join(",", aws_instance.talos_master_instance.*.private_ip)), count.index)
target_id = "${element(split(",", join(",", aws_instance.talos_master_instance.*.private_ip)), count.index)}"
depends_on = [ aws_instance.talos_master_instance ]

}
Expand All @@ -175,7 +163,7 @@ resource "aws_lb_target_group_attachment" "registertarget" {
resource "aws_alb_listener" "talos-listener" {
load_balancer_arn = module.alb.lb_arn
port = 443
protocol = "HTTPS"
protocol = "TCP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.talos-tg.arn
Expand All @@ -185,9 +173,20 @@ resource "aws_alb_listener" "talos-listener" {

resource "null_resource" "bootstrap_etcd" {
provisioner "local-exec" {
command = "/bin/bash scripts/bootstrapetcd.sh ${aws_instance.talos_master_instance.0.public_ip}"
command = "./talosctl --talosconfig scripts/talosconfig config endpoint ${aws_instance.talos_master_instance.0.public_ip}"

}
provisioner "local-exec" {
command = "./talosctl --talosconfig scripts/talosconfig config node ${aws_instance.talos_master_instance.0.public_ip}"

}
provisioner "local-exec" {
command = "sleep 60; ./talosctl --talosconfig scripts/talosconfig bootstrap"
}

provisioner "local-exec" {
command = "./talosctl --talosconfig scripts/talosconfig kubeconfig ."
}
depends_on = [ aws_instance.talos_master_instance ]

}
Loading