-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
69 lines (57 loc) · 2.07 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
data "aws_region" "current" {
}
resource "aws_ecs_cluster" "cluster" {
depends_on = [aws_cloudwatch_log_group.log_group]
name = local.name
tags = merge(local.tags, { type = "operations" })
}
resource "aws_autoscaling_group" "asg" {
lifecycle {
create_before_destroy = true
}
desired_capacity = var.desired_capacity
health_check_type = var.health_check_type
max_size = var.max_size
min_size = var.min_size
launch_configuration = aws_launch_configuration.lc.name
min_elb_capacity = 0
name = "${local.name}-asg"
tags = concat(local.asg_tags, var.instance_tags)
vpc_zone_identifier = var.subnet_ids_cluster
}
resource "aws_launch_configuration" "lc" {
lifecycle {
create_before_destroy = true
}
root_block_device {
# encrypted = true
volume_size = var.root_volume_size
volume_type = var.root_volume_type
}
ebs_block_device {
device_name = "/dev/xvdcz"
encrypted = true
volume_size = var.instance_volume_size
volume_type = var.instance_volume_type
}
name_prefix = "${local.name}-lc"
iam_instance_profile = aws_iam_instance_profile.profile.id
image_id = var.ami_id
instance_type = var.instance_type
user_data = data.template_cloudinit_config.config.rendered
key_name = var.ssh_key_name
// combine alb_instance_sgs defined SGs and the default ECS instance SG for SSH access
security_groups = concat(
[aws_security_group.instance_default_sg.id],
var.alb_instance_sgs,
)
}
resource "aws_security_group_rule" "allow_service" {
count = length(var.allow_to_sgs)
type = "ingress"
from_port = element(split(",", element(var.allow_to_sgs, count.index)), 1)
to_port = element(split(",", element(var.allow_to_sgs, count.index)), 1)
protocol = "tcp"
source_security_group_id = aws_security_group.instance_default_sg.id
security_group_id = element(split(",", element(var.allow_to_sgs, count.index)), 0)
}