-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.tf
253 lines (207 loc) · 6.22 KB
/
demo.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
module "demo-vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "demo-vpc"
cidr = "10.0.0.0/16"
azs = ["sa-east-1a", "sa-east-1b"]
private_subnets = ["10.0.0.0/24", "10.0.1.0/24"]
public_subnets = ["10.0.100.0/24", "10.0.101.0/24"]
enable_nat_gateway = true
single_nat_gateway = true
enable_vpn_gateway = false
tags = {
Environment = "Production"
Type = "Demo"
}
}
module "bastion-sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4.0"
name = "bastion-sg"
description = "Security group for Demo"
vpc_id = module.demo-vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["ssh-tcp"]
egress_rules = ["all-all"]
}
module "bastion" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 2.0"
name = "bastion"
instance_count = 1
ami = "ami-0747bdcabd34c712a"
instance_type = var.instance_type
key_name = "terraform-demo-env"
monitoring = true
vpc_security_group_ids = [ "${module.bastion-sg.security_group_id}" ]
subnet_id = "${module.demo-vpc.public_subnets[0]}"
associate_public_ip_address = true
enable_volume_tags = true
root_block_device = [
{
volume_type = "gp2"
volume_size = 8
},
]
tags = {
Environment = "Production"
Type = "Bastion"
}
}
resource "aws_eip" "bastion" {
instance = "${module.bastion.id[0]}"
vpc = true
}
resource "aws_placement_group" "demo-cluster" {
name = "demo-cluster"
strategy = "cluster"
}
module "proxysql-sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4.0"
name = "bastion-sg"
description = "Security group for Demo"
vpc_id = module.demo-vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["ssh-tcp", "mysql-tcp"]
egress_rules = ["all-all"]
}
module "demo-proxysql-a" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 2.0"
name = "demo-sql-a"
instance_count = 1
placement_group = "${aws_placement_group.demo-cluster.id}"
ami = "ami-0747bdcabd34c712a"
instance_type = var.instance_type
key_name = "terraform-demo-env"
monitoring = true
vpc_security_group_ids = [ "${module.proxysql-sg.security_group_id}" ]
subnet_id = "${module.demo-vpc.private_subnets[0]}"
associate_public_ip_address = false
enable_volume_tags = true
root_block_device = [
{
volume_type = "gp2"
volume_size = 10
},
]
tags = {
Environment = "Production"
Type = "proxySQL"
}
}
# TODO: Add SSM
resource "random_password" "master" {
length = 32
special = true
override_special = "_%@"
}
module "demo-db" {
source = "terraform-aws-modules/rds-aurora/aws"
version = "~> 3.0"
name = "demodb"
engine = "aurora-mysql"
engine_mode = "provisioned"
engine_version = "5.7.mysql_aurora.2.11.0"
instance_type = "db.t3.small"
vpc_id = module.demo-vpc.vpc_id
subnets = module.demo-vpc.private_subnets
create_security_group = true
replica_count = 0
database_name = "demo"
storage_encrypted = true
apply_immediately = true
skip_final_snapshot = true
performance_insights_enabled = true
auto_minor_version_upgrade = false
monitoring_interval = 60
backup_retention_period = 2
preferred_backup_window = "06:00-07:00"
allowed_cidr_blocks = ["0.0.0.0/0"]
create_random_password = false
iam_database_authentication_enabled = false
password = random_password.master.result
db_parameter_group_name = aws_db_parameter_group.demo.id
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.demo.id
enabled_cloudwatch_logs_exports = ["error", "slowquery"]
tags = {
Environment = "Production"
Application = "Demo"
}
}
resource "aws_db_parameter_group" "demo" {
name = "demo-aurora-db-57-parameter-group"
family = "aurora-mysql5.7"
description = "demo-aurora-db-57-parameter-group"
}
resource "aws_rds_cluster_parameter_group" "demo" {
name = "demo-aurora-57-cluster-parameter-group"
family = "aurora-mysql5.7"
description = "demo-aurora-57-cluster-parameter-group"
}
# Create elastic beanstalk application
resource "aws_elastic_beanstalk_application" "elastic_app" {
name = var.elastic_app
}
# Create elastic beanstalk Environment
resource "aws_elastic_beanstalk_environment" "demo-env" {
name = var.beanstalk_app_env
application = aws_elastic_beanstalk_application.elastic_app.name
solution_stack_name = var.solution_stack_name
tier = var.tier
setting {
namespace = "aws:ec2:vpc"
name = "VPCId"
value = module.demo-vpc.vpc_id
}
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "IamInstanceProfile"
value = "aws-elasticbeanstalk-ec2-role"
}
setting {
namespace = "aws:ec2:vpc"
name = "AssociatePublicIpAddress"
value = "True"
}
setting {
namespace = "aws:ec2:vpc"
name = "Subnets"
value = join(",", module.demo-vpc.private_subnets)
}
setting {
namespace = "aws:elasticbeanstalk:environment:process:default"
name = "MatcherHTTPCode"
value = "200"
}
setting {
namespace = "aws:elasticbeanstalk:environment"
name = "LoadBalancerType"
value = "application"
}
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "InstanceType"
value = "t3.micro"
}
setting {
namespace = "aws:ec2:vpc"
name = "ELBScheme"
value = "internet facing"
}
setting {
namespace = "aws:autoscaling:asg"
name = "MinSize"
value = 1
}
setting {
namespace = "aws:autoscaling:asg"
name = "MaxSize"
value = 1
}
setting {
namespace = "aws:elasticbeanstalk:healthreporting:system"
name = "SystemType"
value = "enhanced"
}
}