forked from joshuamkite/terraform-aws-ssh-bastion-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_data.tf
124 lines (108 loc) · 3.13 KB
/
user_data.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
############################
# Templates section
############################
data "template_file" "systemd" {
template = file("${path.module}/user_data/systemd.tpl")
count = local.custom_systemd_no
vars = {
bastion_host_name = local.bastion_host_name
vpc = var.vpc
}
}
data "template_file" "ssh_populate_assume_role" {
count = local.assume_role_yes * local.custom_ssh_populate_no
template = file("${path.module}/user_data/ssh_populate_assume_role.tpl")
vars = {
assume_role_arn = var.assume_role_arn
}
}
data "template_file" "ssh_populate_same_account" {
count = local.assume_role_no * local.custom_ssh_populate_no
template = file("${path.module}/user_data/ssh_populate_same_account.tpl")
}
data "template_file" "docker_setup" {
count = local.custom_docker_setup_no
template = file("${path.module}/user_data/docker_setup.tpl")
vars = {
container_image = var.container_image
}
}
data "template_file" "iam-authorized-keys-command" {
count = local.custom_authorized_keys_command_no
template = file("${path.module}/user_data/iam-authorized-keys-command.tpl")
vars = {
authorized_command_code = file("${path.module}/user_data/iam_authorized_keys_code/main.go")
bastion_allowed_iam_group = var.bastion_allowed_iam_group
}
}
############################
# Templates combined section
############################
data "template_cloudinit_config" "config" {
gzip = false
base64_encode = false
# systemd section
part {
filename = "module_systemd"
content_type = "text/x-shellscript"
content = element(
concat(data.template_file.systemd.*.rendered, ["#!/bin/bash"]),
0,
)
}
# ssh_populate_assume_role
part {
filename = "module_ssh_populate_assume_role"
content_type = "text/x-shellscript"
merge_type = "str(append)"
content = element(
concat(
data.template_file.ssh_populate_assume_role.*.rendered,
["#!/bin/bash"],
),
0,
)
}
# ssh_populate_same_account
part {
filename = "module_ssh_populate_same_account"
content_type = "text/x-shellscript"
merge_type = "str(append)"
content = element(
concat(
data.template_file.ssh_populate_same_account.*.rendered,
["#!/bin/bash"],
),
0,
)
}
# docker_setup section
part {
filename = "module_docker_setup"
content_type = "text/x-shellscript"
merge_type = "str(append)"
content = element(
concat(data.template_file.docker_setup.*.rendered, ["#!/bin/bash"]),
0,
)
}
# iam-authorized-keys-command
part {
filename = "module_iam-authorized-keys-command"
content_type = "text/x-shellscript"
merge_type = "str(append)"
content = element(
concat(
data.template_file.iam-authorized-keys-command.*.rendered,
["#!/bin/bash"],
),
0,
)
}
part {
filename = "extra_user_data"
content_type = var.extra_user_data_content_type
content = var.extra_user_data_content != "" ? var.extra_user_data_content : "#!/bin/bash"
merge_type = var.extra_user_data_merge_type
}
}