forked from joshuamkite/terraform-aws-ssh-bastion-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_data.tf
121 lines (106 loc) · 2.96 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
############################
# Templates section
############################
data "template_file" "systemd" {
template = file("${path.module}/user_data/systemd.tpl")
count = var.custom_systemd ? 0 : 1
vars = {
bastion_host_name = local.bastion_host_name
bastion_ssh_port = var.bastion_ssh_port
host_ssh_port = var.host_ssh_port
vpc = var.vpc_id
}
}
data "template_file" "ssh_populate" {
count = var.custom_ssh_populate ? 0 : 1
template = file("${path.module}/user_data/ssh_populate.tpl")
vars = {
bastion_assume_role_arn = var.bastion_assume_role_arn
aws_region = data.aws_region.current.name
}
}
data "template_file" "cloud_config" {
template = file("${path.module}/user_data/cloud_config.tpl")
vars = {
host_ssh_username = var.host_ssh_username
host_ssh_public_key = var.host_ssh_public_key
}
}
data "template_file" "docker_setup" {
count = var.custom_docker_setup ? 0 : 1
template = file("${path.module}/user_data/docker_setup.tpl")
vars = {
bastion_container_image = var.bastion_container_image
bastion_ssh_port = var.bastion_ssh_port
}
}
data "template_file" "iam-authorized-keys" {
count = var.custom_authorized_keys_command ? 0 : 1
template = file("${path.module}/user_data/iam-authorized-keys.tpl")
vars = {
iam_authorized_keys_version = "2.2.0"
}
}
############################
# Templates combined section
############################
data "template_cloudinit_config" "config" {
gzip = false
base64_encode = true
part {
content_type = "text/cloud-config"
filename = "init.cfg"
content = data.template_file.cloud_config.rendered
}
# 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"
content_type = "text/x-shellscript"
merge_type = "str(append)"
content = element(
concat(
data.template_file.ssh_populate.*.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"
content_type = "text/x-shellscript"
merge_type = "str(append)"
content = element(
concat(
data.template_file.iam-authorized-keys.*.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
}
}