-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
108 lines (86 loc) · 3.88 KB
/
main.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
locals {
# TODO: populate this from var.management_region_aws (TFC Var Set)
management_region_aws = "us-west-2"
authoritative_region = "aws-${local.management_region_aws}"
join_tag_tags = "tag_key=nomad:role tag_value=server addr_type=public_v4"
nomad_region = "aws-${var.aws_region}"
# assemble dynamic User Data and associated Nomad configuration files
# see https://developer.hashicorp.com/terraform/language/functions/templatefile
client_config_nomad = templatefile("${path.module}/templates/nomad-client-config.tftpl.hcl", {
datacenter = "aws"
join_tags = [
"provider=aws region=${var.aws_region} ${local.join_tag_tags}",
]
region = local.nomad_region
})
# see https://developer.hashicorp.com/terraform/language/functions/base64encode
# and https://developer.hashicorp.com/terraform/language/functions/templatefile
client_user_data = base64encode(templatefile("${path.module}/templates/user-data.tftpl.sh", {
NOMAD_CONFIG_DATA = base64encode(local.client_config_nomad)
}))
# see https://developer.hashicorp.com/terraform/language/functions/templatefile
server_config_nomad = templatefile("${path.module}/templates/nomad-server-config.tftpl.hcl", {
authoritative_region = local.authoritative_region
datacenter = "aws"
join_tags = [
# discover Nomad Servers in the same AWS Region
"provider=aws region=${var.aws_region} ${local.join_tag_tags}",
# discover Nomad Servers in the authoritative AWS Region
"provider=aws region=${local.management_region_aws} ${local.join_tag_tags}",
]
region = local.nomad_region
})
# see https://developer.hashicorp.com/terraform/language/functions/base64encode
# and https://developer.hashicorp.com/terraform/language/functions/templatefile
server_user_data = base64encode(templatefile("${path.module}/templates/user-data.tftpl.sh", {
NOMAD_CONFIG_DATA = base64encode(local.server_config_nomad)
}))
}
locals {
deployments = {
# Nomad Client-specific configuration
client = {
autoscaling_group_desired_capacity = 3
autoscaling_group_max_size = 3
autoscaling_group_min_size = 1
iam_name = "nomad-clients-${local.name_suffix}"
iam_policy_description = "Nomad Cient-specific Policy"
iam_policy_document = data.aws_iam_policy_document.iam_policy_client.json
iam_role_policy_document = data.aws_iam_policy_document.iam_role.json
iam_role_name = local.name_suffix
launch_template_block_device_mappings = {
# root device for Ubuntu 22.04 LTS
device_name = "/dev/sda1"
ebs_volume_size = 50 # size in GB
}
launch_template_instance_type = var.launch_template_instance_type_client
launch_template_tags_instance = {
"nomad:role" = "client"
"service:nomad" = "true"
}
launch_template_user_data = local.client_user_data
}
# Nomad Server-specific configuration
server = {
autoscaling_group_desired_capacity = 3
autoscaling_group_max_size = 3
autoscaling_group_min_size = 3
iam_name = "nomad-servers-${local.name_suffix}"
iam_policy_description = "Nomad Server-specific Policy"
iam_policy_document = data.aws_iam_policy_document.iam_policy_server.json
iam_role_policy_document = data.aws_iam_policy_document.iam_role.json
iam_role_name = local.name_suffix
launch_template_block_device_mappings = {
# root device for Ubuntu 22.04 LTS
device_name = "/dev/sda1"
ebs_volume_size = 50 # size in GB
}
launch_template_instance_type = var.launch_template_instance_type_server
launch_template_tags_instance = {
"nomad:role" = "server"
"service:nomad" = "true"
}
launch_template_user_data = local.server_user_data
}
}
}