-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
131 lines (100 loc) · 4.13 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
resource "random_pet" "this" {}
module "label" {
source = "github.com/robc-io/terraform-null-label.git?ref=0.16.1"
tags = {
NetworkName = var.network_name
Owner = var.owner
Terraform = true
VpcType = "main"
}
environment = var.environment
namespace = var.namespace
stage = var.stage
}
module "user_data" {
source = "github.com/insight-infrastructure/terraform-polkadot-user-data.git?ref=master"
type = var.node_purpose
cloud_provider = "aws"
driver_type = var.storage_driver_type
mount_volumes = var.mount_volumes
}
resource "aws_key_pair" "this" {
count = var.key_name == "" && var.create ? 1 : 0
public_key = var.public_key
}
resource "aws_eip" "this" {
count = var.create ? 1 : 0
vpc = true
lifecycle {
prevent_destroy = false
}
tags = module.label.tags
}
resource "aws_eip_association" "this" {
count = var.create ? 1 : 0
allocation_id = aws_eip.this.*.id[count.index]
instance_id = join("", aws_instance.this.*.id)
}
resource "aws_instance" "this" {
count = var.create ? 1 : 0
instance_type = var.instance_type
ami = data.aws_ami.ubuntu.id
user_data = module.user_data.user_data
subnet_id = var.subnet_id
vpc_security_group_ids = [var.security_group_id]
monitoring = var.monitoring
key_name = concat(aws_key_pair.this.*.key_name, [var.key_name])[0]
root_block_device {
volume_type = "gp2"
volume_size = var.root_volume_size
delete_on_termination = true
}
tags = merge({ Name : var.node_name }, module.label.tags)
}
module "ansible" {
source = "github.com/insight-infrastructure/terraform-aws-ansible-playbook.git?ref=v0.12.0"
create = var.create_ansible && var.create
ip = join("", aws_eip_association.this.*.public_ip)
user = "ubuntu"
private_key_path = var.private_key_path
playbook_file_path = "${path.module}/ansible/${var.node_purpose}.yml"
requirements_file_path = "${path.module}/ansible/requirements.yml"
forks = 1
playbook_vars = {
id = module.label.id
ssh_user = var.ssh_user
# enable flags
node_exporter_enabled = var.node_exporter_enabled
health_check_enabled = var.health_check_enabled
consul_enabled = var.consul_enabled
use_source_of_truth = var.source_of_truth_enabled
# node exporter
node_exporter_user = var.node_exporter_user
node_exporter_password = var.node_exporter_password
node_exporter_binary_url = var.node_exporter_url
node_exporter_binary_checksum = "sha256:${var.node_exporter_hash}"
# polkadot client
polkadot_binary_url = var.polkadot_client_url
polkadot_binary_checksum = "sha256:${var.polkadot_client_hash}"
polkadot_restart_enabled = var.polkadot_restart_enabled
polkadot_restart_minute = var.polkadot_restart_minute
polkadot_restart_hour = var.polkadot_restart_hour
polkadot_restart_day = var.polkadot_restart_day
polkadot_restart_month = var.polkadot_restart_month
polkadot_restart_weekday = var.polkadot_restart_weekday
network_settings = jsonencode(local.network_settings)
aws_access_key_id = local.create_source_of_truth ? aws_iam_access_key.sync[0].id : var.sync_aws_access_key_id
aws_secret_access_key = local.create_source_of_truth ? aws_iam_access_key.sync[0].secret : var.sync_aws_secret_access_key
region = var.sync_region
sync_bucket_uri = local.create_source_of_truth ? aws_s3_bucket.sync[0].bucket_domain_name : var.sync_bucket_uri
project = var.project
instance_count = var.instance_count
loggingFilter = var.logging_filter
telemetryUrl = var.telemetry_url
default_telemetry_enabled = var.default_telemetry_enabled
base_path = var.base_path
polkadot_additional_common_flags = var.polkadot_additional_common_flags
polkadot_additional_validator_flags = var.polkadot_additional_validator_flags
}
module_depends_on = aws_instance.this
}