-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2_jumphost.tf
55 lines (42 loc) · 1.37 KB
/
ec2_jumphost.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
data "aws_ssm_parameter" "ecs_optimized" {
name = "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id"
}
resource "aws_key_pair" "default" {
public_key = var.public_key
}
# used just for debugging from within the VPC; not necessary
resource "aws_instance" "jumphost" {
subnet_id = module.vpc.subnet_public1
ami = data.aws_ssm_parameter.ecs_optimized.value
instance_type = "t3.medium"
vpc_security_group_ids = [
module.vpc.sg_allow_vpc,
module.vpc.sg_allow_22,
module.vpc.sg_allow_egress,
aws_security_group.splunk.id # hack to allow it to mount the EFS volume
]
key_name = aws_key_pair.default.key_name
iam_instance_profile = aws_iam_instance_profile.ec2.name
}
data "aws_iam_policy_document" "ec2_assume" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role" "jumphost" {
name = "${local.name}-jumphost"
assume_role_policy = data.aws_iam_policy_document.ec2_assume.json
}
resource "aws_iam_role_policy_attachment" "jumphost_ssm" {
role = aws_iam_role.jumphost.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
resource "aws_iam_instance_profile" "ec2" {
name = "${aws_iam_role.jumphost.name}-instance-profile"
role = aws_iam_role.jumphost.name
}