This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
forked from Kong/kong-terraform-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2.tf
111 lines (95 loc) · 2.97 KB
/
ec2.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
resource "aws_launch_configuration" "kong" {
name_prefix = format("%s-%s-", var.service, var.environment)
image_id = var.ec2_ami[data.aws_region.current.name]
instance_type = var.ec2_instance_type
iam_instance_profile = aws_iam_instance_profile.kong.name
key_name = var.ec2_key_name
security_groups = [
# data.aws_security_group.default.id,
aws_security_group.kong.id,
]
associate_public_ip_address = false
enable_monitoring = true
placement_tenancy = "default"
user_data = data.template_cloudinit_config.cloud-init.rendered
root_block_device {
volume_size = var.ec2_root_volume_size
volume_type = var.ec2_root_volume_type
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "kong" {
name = format("%s-%s", var.service, var.environment)
vpc_zone_identifier = data.aws_subnet_ids.private.ids
launch_configuration = aws_launch_configuration.kong.name
desired_capacity = var.asg_desired_capacity
force_delete = false
health_check_grace_period = var.asg_health_check_grace_period
health_check_type = "ELB"
max_size = var.asg_max_size
min_size = var.asg_min_size
target_group_arns = compact(
concat(
aws_lb_target_group.external.*.arn,
aws_lb_target_group.internal.*.arn,
aws_lb_target_group.admin.*.arn,
aws_lb_target_group.manager.*.arn,
aws_lb_target_group.portal-gui.*.arn,
aws_lb_target_group.portal.*.arn
)
)
tag {
key = "Name"
value = format("%s-%s", var.service, var.environment)
propagate_at_launch = true
}
tag {
key = "Environment"
value = var.environment
propagate_at_launch = true
}
tag {
key = "Description"
value = var.description
propagate_at_launch = true
}
tag {
key = "Service"
value = var.service
propagate_at_launch = true
}
dynamic "tag" {
for_each = var.tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
depends_on = [
aws_db_instance.kong,
aws_rds_cluster.kong
]
}
resource "aws_instance" "kong-jumpbox" {
ami = var.ec2_ami[data.aws_region.current.name]
instance_type = var.ec2_instance_type
key_name = var.ec2_key_name
associate_public_ip_address = true
vpc_security_group_ids = [
# data.aws_security_group.default.id,
aws_security_group.jumpbox.id,
]
subnet_id = sort(data.aws_subnet_ids.public.ids)[0]
tags = merge(
{
"Name" = format("%s-%s-jumpbox", var.service, var.environment),
"Environment" = var.environment,
"Description" = var.description,
"Service" = var.service,
},
var.tags
)
}