-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.tf
43 lines (34 loc) · 1.78 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
# ---------------------------------------------------------------------------------------------------------------------
# DEPLOY THE CONSUL SERVER NODES
# ---------------------------------------------------------------------------------------------------------------------
module "consul_servers" {
source = "git::https://github.com/hashicorp/terraform-aws-consul.git//modules/consul-cluster?ref=v0.8.4"
cluster_name = var.cluster_tag_value
cluster_size = var.num_servers
instance_type = var.instance_type
# The EC2 Instances will use these tags to automatically discover each other and form a cluster
cluster_tag_key = var.cluster_tag_key
cluster_tag_value = var.cluster_tag_value
ami_id = var.ami_id
user_data = data.template_file.user_data_consul_server.rendered
vpc_id = var.vpc_id
subnet_ids = var.subnet_ids
allowed_ssh_cidr_blocks = var.allowed_ssh_cidr_blocks
allowed_inbound_cidr_blocks = []
allowed_inbound_security_group_count = 0
ssh_key_name = var.ssh_key_name
# Inject own instance profile with AWS SSM support
enable_iam_setup = false
iam_instance_profile_name = aws_iam_instance_profile.instance_profile.name
}
# ---------------------------------------------------------------------------------------------------------------------
# THE USER DATA SCRIPT THAT WILL RUN ON EACH CONSUL SERVER EC2 INSTANCE WHEN IT'S BOOTING
# This script will configure and start Consul
# ---------------------------------------------------------------------------------------------------------------------
data "template_file" "user_data_consul_server" {
template = file("${path.module}/user-data-consul-server.sh")
vars = {
cluster_tag_key = var.cluster_tag_key
cluster_tag_value = var.cluster_tag_value
}
}