Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit f0d5b7f

Browse files
committed
New: module bastion
Setup a ssh bastion for specified VPC. This is useful when managing a VPC. Simply a single node ASG (with EIP) with SSH-in allowed.
1 parent 683992c commit f0d5b7f

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

examples/bastion-test/tester.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
variable "region" {
2+
description = "The region to put resources in"
3+
default = "us-east-1"
4+
}
5+
6+
variable "az" {
7+
description = "The availability zone to put resources in"
8+
default = "us-east-1c"
9+
}
10+
11+
variable "key_name" {
12+
description = "The keypair used to ssh into the asg intances"
13+
default = "shida-east-1"
14+
}
15+
16+
provider "aws" {
17+
region = var.region
18+
}
19+
20+
module "vpc" {
21+
source = "../../modules/vpc-scenario-1"
22+
azs = [var.az]
23+
name_prefix = "bastion-test"
24+
cidr = "192.168.0.0/16"
25+
public_subnet_cidrs = ["192.168.0.0/16"]
26+
region = var.region
27+
map_on_launch = false
28+
}
29+
30+
module "bastion" {
31+
source = "../../modules/bastion"
32+
region = var.region
33+
key_name = var.key_name
34+
public_subnet_id = module.vpc.public_subnet_ids[0]
35+
identifier = "test"
36+
vpc_id = module.vpc.vpc_id
37+
}

examples/single-node-asg-test/tester.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module "snasg" {
3737
key_name = var.key_name
3838
subnet_id = module.vpc.public_subnet_ids[0]
3939
security_group_ids = [aws_security_group.eiptest.id]
40-
assign_eip = true
40+
assign_eip = false # true case is tested in bastion-test example
4141
}
4242

4343
module "ubuntu-ami" {

modules/bastion/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SSH Bastion
2+
3+
This is a module to provide a bastion to access the inside of a VPC from Internet.

modules/bastion/main.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
variable "vpc_id" {
2+
type = string
3+
description = "ID of the VPC."
4+
}
5+
6+
variable "identifier" {
7+
type = string
8+
description = "Identifier of related resources."
9+
}
10+
11+
variable "region" {
12+
type = string
13+
description = "AWS region for this bastion to be in."
14+
}
15+
16+
variable "key_name" {
17+
type = string
18+
description = "SSH key pair name for the bastion."
19+
}
20+
21+
variable "public_subnet_id" {
22+
type = string
23+
description = "The subnet for the bastion. The subnet must be able to access Internet."
24+
}
25+
26+
module "instance" {
27+
source = "../single-node-asg"
28+
name_prefix = var.identifier
29+
name_suffix = "bastion"
30+
ami = module.ubuntu-ami.id
31+
instance_type = "t2.nano"
32+
region = var.region
33+
key_name = var.key_name
34+
subnet_id = var.public_subnet_id
35+
security_group_ids = [aws_security_group.bastion.id]
36+
assign_eip = true
37+
}
38+
39+
resource "aws_security_group" "bastion" {
40+
name = "${var.identifier}-bastion"
41+
vpc_id = var.vpc_id
42+
}
43+
44+
module "bastion-ssh-rule" {
45+
source = "../../modules/ssh-sg"
46+
cidr_blocks = ["0.0.0.0/0"]
47+
security_group_id = aws_security_group.bastion.id
48+
}
49+
50+
module "bastion-egress-rule" {
51+
source = "../../modules/open-egress-sg"
52+
security_group_id = aws_security_group.bastion.id
53+
}
54+
55+
module "ubuntu-ami" {
56+
source = "../../modules/ami-ubuntu"
57+
release = "18.04"
58+
}

0 commit comments

Comments
 (0)