-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappserver.tf
More file actions
140 lines (118 loc) · 4.14 KB
/
appserver.tf
File metadata and controls
140 lines (118 loc) · 4.14 KB
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
# -----------------------------------------------------------------------------
# Key Pair
# -----------------------------------------------------------------------------
resource "aws_key_pair" "keypair" {
key_name = "${var.project}-${var.environment}-keypair"
public_key = file("./src/tastylog-dev-keypair.pub")
tags = {
Name = "${var.project}-${var.environment}-keypair"
Project = var.project
Env = var.environment
}
}
# -----------------------------------------------------------------------------
# Parameteter Store
# -----------------------------------------------------------------------------
resource "aws_ssm_parameter" "host" {
name = "/${var.project}/${var.environment}/app/MYSQL_HOST"
type = "String"
value = aws_db_instance.mysql-standalone.address
}
resource "aws_ssm_parameter" "port" {
name = "/${var.project}/${var.environment}/app/MYSQL_PORT"
type = "String"
value = aws_db_instance.mysql-standalone.port
}
resource "aws_ssm_parameter" "database" {
name = "/${var.project}/${var.environment}/app/MYSQL_DATABASE"
type = "String"
value = aws_db_instance.mysql-standalone.db_name
}
resource "aws_ssm_parameter" "username" {
name = "/${var.project}/${var.environment}/app/MYSQL_USERNAME"
type = "SecureString"
value = aws_db_instance.mysql-standalone.username
}
resource "aws_ssm_parameter" "password" {
name = "/${var.project}/${var.environment}/app/MYSQL_PASSWORD"
type = "SecureString"
value = aws_db_instance.mysql-standalone.password
}
# # -----------------------------------------------------------------------------
# # EC2 Instance
# # -----------------------------------------------------------------------------
# resource "aws_instance" "app_server" {
# ami = data.aws_ami.app.id
# instance_type = "t2.micro"
# subnet_id = aws_subnet.public_subnet_1a.id
# associate_public_ip_address = true
# iam_instance_profile = aws_iam_instance_profile.app_ec2_profile.name
# vpc_security_group_ids = [aws_security_group.app_sg.id, aws_security_group.opmng_sg.id]
# key_name = aws_key_pair.keypair.key_name
# user_data = file("./src/userdata/appserver.sh")
# tags = {
# Name = "${var.project}-${var.environment}-app-ec2"
# Project = var.project
# Env = var.environment
# Type = "app"
# }
# }
# -----------------------------------------------------------------------------
# Launch Template
# -----------------------------------------------------------------------------
resource "aws_launch_template" "app_lt" {
update_default_version = true
name = "${var.project}-${var.environment}-app.lt"
image_id = data.aws_ami.app.id
key_name = aws_key_pair.keypair.key_name
tag_specifications {
resource_type = "instance"
tags = {
Name = "${var.project}-${var.environment}-app-ec2"
Project = var.project
Env = var.environment
Type = "app"
}
}
network_interfaces {
associate_public_ip_address = true
security_groups = [
aws_security_group.app_sg.id,
aws_security_group.opmng_sg.id
]
delete_on_termination = true
}
iam_instance_profile {
name = aws_iam_instance_profile.app_ec2_profile.name
}
user_data = filebase64("./src/userdata/initialize.sh")
}
# -----------------------------------------------------------------------------
#
# -----------------------------------------------------------------------------
resource "aws_autoscaling_group" "app_asg" {
name = "${var.project}-${var.environment}-app-asg"
max_size = 1
min_size = 1
desired_capacity = 1
health_check_grace_period = 300
health_check_type = "ELB"
vpc_zone_identifier = [
aws_subnet.public_subnet_1a.id,
aws_subnet.public_subnet_1c.id
]
target_group_arns = [
aws_lb_target_group.alb_target_group.arn
]
mixed_instances_policy {
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.app_lt.id
version = "$Latest"
}
override {
instance_type = "t2.micro"
}
}
}
}