-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbastion.tf
74 lines (63 loc) · 2.73 KB
/
bastion.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
locals {
bastion_subnet_ids = "${split(",", length(var.bastion_pool_subnet_ids) == 0 ? join(",", local.public_subnet_ids) : join(",", var.bastion_pool_subnet_ids))}"
bastion_instance_profile = "${var.bastion_pool_iam_instance_profile_name != "" ? var.bastion_pool_iam_instance_profile_name : join("", aws_iam_instance_profile.node_profile.*.id)}"
}
variable "bastion_pool_count" {
description = "Number of bastion nodes"
default = 0
}
variable "bastion_pool_instance_type" {
description = "[BASTION] Instance type"
default = "t3.small"
}
variable "bastion_pool_image_id" {
description = "[BASTION] AWS AMI image ID that will be used for the instances instead of the Mesosphere chosen default images"
default = ""
}
variable "bastion_pool_root_volume_size" {
description = "[BASTION] The root volume size"
default = "10"
}
variable "bastion_pool_root_volume_type" {
description = "[BASTION] The root volume type. Should be gp2 or io1"
default = "gp2"
}
variable "bastion_pool_subnet_ids" {
type = "list"
description = "[BASTION] Subnet to be used to deploy bastions on"
default = []
}
variable "bastion_pool_iam_instance_profile_name" {
description = "Pre-existing iam instanceProfile name to use"
default = ""
}
resource "aws_instance" "bastion" {
vpc_security_group_ids = ["${aws_security_group.konvoy_private.id}", "${aws_security_group.konvoy_ssh.id}", "${aws_security_group.konvoy_egress.id}"]
subnet_id = "${element(local.bastion_subnet_ids, count.index % length(local.bastion_subnet_ids))}"
key_name = "${local.cluster_name}"
count = "${var.bastion_pool_count > 0 ? var.bastion_pool_count : 0}"
ami = "${var.bastion_pool_image_id != "" ? var.bastion_pool_image_id : lookup(local.default_ami_ids, format("centos7_%s", coalesce(var.aws_region, data.aws_region.current.name)))}"
instance_type = "${var.bastion_pool_instance_type}"
availability_zone = "${element(coalescelist(var.aws_availability_zones, data.aws_availability_zones.available.names), count.index)}"
iam_instance_profile = "${local.bastion_instance_profile}"
source_dest_check = "false"
associate_public_ip_address = "true"
root_block_device {
volume_size = "${var.bastion_pool_root_volume_size}"
volume_type = "${var.bastion_pool_root_volume_type}"
delete_on_termination = true
}
tags = "${merge(
local.common_tags,
map(
"Name", "${local.cluster_name}-bastion-${count.index}",
"konvoy/nodeRoles", "bastion"
)
)}"
volume_tags = "${merge(
local.common_tags_no_cluster,
map(
"konvoy/nodeRoles", "bastion"
)
)}"
}