-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
167 lines (143 loc) · 5.85 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
########### Security Group for brokerMQ #########
module "arc_security_group" {
source = "sourcefuse/arc-security-group/aws"
version = "0.0.1"
name = "${var.namespace}-${var.environment}-${var.name}-broker-mq-sg"
vpc_id = var.vpc_id
ingress_rules = var.security_group_data.ingress_rules
egress_rules = var.security_group_data.egress_rules
tags = var.tags
}
######### Generate a random password #########
resource "random_password" "mq_broker" {
length = 32
special = true
upper = true
lower = true
numeric = true
override_special = "!@#$%^&*()-_+<>?"
}
######### Store the generated password in ssm #########
resource "aws_ssm_parameter" "user_password" {
name = "/${var.namespace}/${var.environment}/${var.name}/mq/broker/user_password"
type = "SecureString"
value = random_password.mq_broker.result
}
resource "aws_ssm_parameter" "replication_user_password" {
count = var.broker_type == "ActiveMQ" ? 1 : 0
name = "/${var.namespace}/${var.environment}/${var.name}/mq/broker/replication_user_password"
type = "SecureString"
value = random_password.mq_broker.result
}
resource "aws_ssm_parameter" "user_name" {
name = "/${var.namespace}/${var.environment}/${var.name}/mq/broker/user_name"
type = "SecureString"
value = var.users.username
}
resource "aws_ssm_parameter" "replication_user" {
count = var.broker_type == "ActiveMQ" ? 1 : 0
name = "/${var.namespace}/${var.environment}/${var.name}/mq/broker/replication_user_name"
type = "SecureString"
value = var.users.username
}
########################################################################
############################# RabiitMQ ##############################
########################################################################
resource "aws_mq_broker" "rabbit-mq" {
count = var.broker_type == "RabbitMQ" ? 1 : 0
broker_name = var.name
engine_type = var.broker_type
engine_version = var.engine_version
host_instance_type = var.host_instance_type
security_groups = var.publicly_accessible ? null : [module.arc_security_group.id]
subnet_ids = var.publicly_accessible ? null : var.subnet_ids
publicly_accessible = var.publicly_accessible
deployment_mode = var.deployment_mode
storage_type = var.storage_type
apply_immediately = var.apply_immediately
auto_minor_version_upgrade = var.auto_minor_version_upgrade
user {
username = var.users.username
password = aws_ssm_parameter.user_password.value
groups = var.users.groups
}
dynamic "logs" {
for_each = var.enable_logging ? [1] : []
content {
general = true
}
}
encryption_options {
use_aws_owned_key = var.encryption_options.use_aws_owned_key
kms_key_id = var.encryption_options.kms_key_id
}
maintenance_window_start_time {
day_of_week = var.maintenance_window.day_of_week
time_of_day = var.maintenance_window.time_of_day
time_zone = var.maintenance_window.time_zone
}
tags = var.tags
}
########################################################################
######################## Apache ActiveMQ ############################
########################################################################
resource "aws_mq_broker" "active-mq" {
count = var.broker_type == "ActiveMQ" ? 1 : 0
broker_name = var.name
engine_type = var.broker_type
engine_version = var.engine_version
host_instance_type = var.host_instance_type
security_groups = [module.arc_security_group.id]
subnet_ids = var.subnet_ids
publicly_accessible = var.publicly_accessible
deployment_mode = var.deployment_mode
storage_type = var.storage_type
apply_immediately = var.apply_immediately
auto_minor_version_upgrade = var.auto_minor_version_upgrade
user {
username = var.users.username
password = aws_ssm_parameter.replication_user_password[0].value
groups = var.users.groups
}
user {
username = var.users_replica.replication_username
password = aws_ssm_parameter.replication_user_password[0].value
groups = var.users_replica.groups
replication_user = true
}
dynamic "logs" {
for_each = var.enable_logging ? [1] : []
content {
general = true
audit = true
}
}
encryption_options {
use_aws_owned_key = var.encryption_options.use_aws_owned_key
kms_key_id = var.encryption_options.kms_key_id
}
maintenance_window_start_time {
day_of_week = var.maintenance_window.day_of_week
time_of_day = var.maintenance_window.time_of_day
time_zone = var.maintenance_window.time_zone
}
data_replication_mode = var.enable_data_replication ? "CRDR" : null
data_replication_primary_broker_arn = var.enable_data_replication ? var.data_replication_primary_broker_arn : null
dynamic "ldap_server_metadata" {
for_each = var.ldap_config.required ? [1] : []
content {
hosts = var.ldap_config.hosts
role_base = var.ldap_config.role_base
role_name = var.ldap_config.role_name
role_search_matching = var.ldap_config.role_search_matching
role_search_subtree = var.ldap_config.role_search_subtree
service_account_password = var.ldap_config.service_account_password
service_account_username = var.ldap_config.service_account_username
user_base = var.ldap_config.user_base
user_role_name = var.ldap_config.user_role_name
user_search_matching = var.ldap_config.user_search_matching
user_search_subtree = var.ldap_config.user_search_subtree
}
}
tags = var.tags
}