Skip to content

Commit

Permalink
bastion: add bastion host
Browse files Browse the repository at this point in the history
  • Loading branch information
furiousme committed Oct 20, 2024
1 parent 575a86f commit 5cb3b22
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
16 changes: 16 additions & 0 deletions bastion.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "aws_instance" "terraform_course_bastion" {
ami = "ami-06b21ccaeff8cd686"
instance_type = "t2.micro"
subnet_id = aws_subnet.terraform_course_public_subnet_1.id
key_name = var.ec2_key_name
security_groups = [aws_security_group.terraform_course_bastion_sg.id]

tags = {
Name = "terraform_course_bastion"
}
}

output "terraform_course_bastion_ip_addr" {
value = aws_instance.terraform_course_bastion.public_ip
sensitive = true
}
24 changes: 23 additions & 1 deletion securitygroups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,26 @@ resource "aws_security_group" "terraform_course_private_subnet_sg" {
tags = {
Name = "terraform_course_private_subnet_sg"
}
}
}

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

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${var.ip_address}/32"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Name = "terraform_course_bastion_sg"
}
}
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ variable "private_subnet_2_cidr" {
variable "az" {
type = list(string)
default = ["us-east-1a", "us-east-1b", "us-east-1c"]
}

variable "ip_address" {
type = string
sensitive = true
}

variable "ec2_key_name" {
type = string
sensitive = true
}

0 comments on commit 5cb3b22

Please sign in to comment.