-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.tf
139 lines (128 loc) · 3.98 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
132
133
134
135
136
137
138
139
# Terraform setup stuff, required providers, where they are sourced from, and
# the provider's configuration requirements.
terraform {
required_providers {
hiera5 = {
source = "chriskuchin/hiera5"
version = "0.3.0"
}
aws = {
source = "hashicorp/aws"
version = "5.20.1"
}
random = {
source = "hashicorp/random"
version = "3.1.0"
}
}
}
# Sets the variables that'll be interpolated to determine where variables are
# located in the hierarchy
provider "hiera5" {
scope = {
architecture = var.architecture
replica = var.replica
profile = var.cluster_profile
}
}
provider "aws" {
region = var.region
default_tags {
tags = var.tags
}
}
# hiera lookups
data "hiera5" "server_count" {
key = "server_count"
}
data "hiera5" "database_count" {
key = "database_count"
}
data "hiera5_bool" "has_compilers" {
key = "has_compilers"
}
data "hiera5" "compiler_type" {
key = "compiler_instance_type"
}
data "hiera5" "primary_type" {
key = "primary_instance_type"
}
data "hiera5" "database_type" {
key = "database_instance_type"
}
data "hiera5" "compiler_disk" {
key = "compiler_disk_size"
}
data "hiera5" "primary_disk" {
key = "primary_disk_size"
}
data "hiera5" "database_disk" {
key = "database_disk_size"
}
# Prevent name collisions when multiple PE deployments are provisioned within
# the same AWS account
resource "random_id" "deployment" {
byte_length = 3
}
# Repeated and computed values used by component modules
locals {
allowed = concat(["10.128.0.0/9"], var.firewall_allow)
compiler_count = data.hiera5_bool.has_compilers.value ? var.compiler_count : 0
id = random_id.deployment.hex
has_lb = var.disable_lb ? false : data.hiera5_bool.has_compilers.value ? true : false
image_list = split("/", var.instance_image)
image_owner = local.image_list[0]
image_pattern = local.image_list[1]
image_product_code = try(local.image_list[2], null)
create_network = var.subnet == null ? true : false
}
# Contain all the networking configuration for readability
module "networking" {
source = "./modules/networking"
id = local.id
project = var.project
allow = local.allowed
to_create = local.create_network
subnet = var.subnet
}
# Contain all the loadbalancer configuration for readability
module "loadbalancer" {
source = "./modules/loadbalancer"
id = local.id
vpc_id = module.networking.vpc_id
ports = ["8140", "8142"]
security_group_ids = module.networking.security_group_ids
subnet_ids = module.networking.subnet_ids
project = var.project
instances = module.instances.compilers
has_lb = local.has_lb
compiler_count = local.compiler_count
lb_ip_mode = var.lb_ip_mode
}
# Contain all the instances configuration for readability
#
module "instances" {
source = "./modules/instances"
vpc_id = module.networking.vpc_id
subnet_ids = module.networking.subnet_ids
security_group_ids = module.networking.security_group_ids
id = local.id
user = var.user
ssh_key = var.ssh_key
compiler_count = local.compiler_count
node_count = var.node_count
instance_image = local.image_pattern
image_owner = local.image_owner
image_product_code = local.image_product_code
tags = var.tags
project = var.project
server_count = data.hiera5.server_count.value
database_count = data.hiera5.database_count.value
compiler_type = data.hiera5.compiler_type.value
primary_type = data.hiera5.primary_type.value
database_type = data.hiera5.database_type.value
compiler_disk = data.hiera5.compiler_disk.value
primary_disk = data.hiera5.primary_disk.value
database_disk = data.hiera5.database_disk.value
domain_name = var.domain_name
}