Skip to content

Commit

Permalink
fix: fix users scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
furiousme committed Oct 23, 2024
1 parent 9d50d28 commit 7594088
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bastion.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_instance" "terraform_course_bastion" {
ami = "ami-0ddc798b3f1a5117e"
ami = var.ami
instance_type = "t2.micro"
subnet_id = aws_subnet.terraform_course_public_subnet_1.id
key_name = var.ec2_key_name
Expand Down
26 changes: 19 additions & 7 deletions cluster.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
resource "aws_instance" "terraform_course_k8s_server" {
ami = "ami-0ddc798b3f1a5117e"
ami = var.ami
instance_type = "t2.micro"
subnet_id = aws_subnet.terraform_course_private_subnet_1.id
key_name = var.ec2_key_name
security_groups = [aws_security_group.terraform_course_k8s_sg.id]

user_data = templatefile("k8s_server.sh", {})
user_data = <<-EOF
#!/bin/bash
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.21.3+k3s1 sh -s - server \
--token=${var.k3s_token} \
--disable traefik
chmod 644 /etc/rancher/k3s/k3s.yaml
EOF

user_data_replace_on_change = true

tags = {
Name = "terraform_course_k8s_server"
}
}

resource "aws_instance" "terraform_course_k8s_agent" {
ami = "ami-0ddc798b3f1a5117e"
ami = var.ami
instance_type = "t2.micro"
subnet_id = aws_subnet.terraform_course_private_subnet_2.id
key_name = var.ec2_key_name
security_groups = [aws_security_group.terraform_course_k8s_sg.id]
depends_on = [aws_instance.terraform_course_k8s_server]

user_data = templatefile("k8s_agent.sh", {
token = var.k8s_token,
server_private_ip = aws_instance.terraform_course_k8s_server.private_ip
})
user_data = <<-EOF
#!/bin/bash
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.21.3+k3s1 K3S_URL=https://${aws_instance.terraform_course_k8s_server.private_ip}:6443 K3S_TOKEN=${var.k3s_token} sh -
chmod 644 /etc/rancher/k3s/k3s.yaml
EOF


user_data_replace_on_change = true

tags = {
Name = "terraform_course_k8s_agent"
Expand Down
9 changes: 9 additions & 0 deletions securitygroups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,21 @@ resource "aws_security_group" "terraform_course_bastion_sg" {

resource "aws_security_group" "terraform_course_k8s_sg" {
vpc_id = aws_vpc.terraform_course_main_vpc.id

ingress {
from_port = 6443
to_port = 6443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${aws_instance.terraform_course_bastion.private_ip}/32"]
}

egress {
from_port = 0
to_port = 0
Expand Down
7 changes: 6 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ variable "ec2_key_name" {
sensitive = true
}

variable "k8s_token" {
variable "k3s_token" {
type = string
sensitive = true
}

variable "ami" {
type = string
default = "ami-06b21ccaeff8cd686"
}

0 comments on commit 7594088

Please sign in to comment.