-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-ecs.tf
96 lines (77 loc) · 2.73 KB
/
02-ecs.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
module "ecs" {
source = "./modules/it-fs-terraform-mod-ecs"
account_prefix = "${var.account_shorthand}"
environment = "${var.environment}"
project = "${var.project}"
service = "${var.service}"
owner = "${var.owner}"
expiration_date = "${var.expiration_date}"
monitor = "${var.ecs_monitor}"
cost_center = "${var.cost_center}"
extra_tags = "${var.tags}"
vpc_id = "${module.vpc.vpc_id}"
lookup_latest_ami = true
instance_type = "${var.ecs_instance_type}"
key_name = "${var.ecs_enable_ssh ? aws_key_pair.ecs_host_key.key_name : ""}"
private_subnet_ids = [ "${module.vpc.private_subnets}" ]
root_block_device_type = "gp2"
root_block_device_size = "${var.ecs_instance_root_size}"
health_check_grace_period = "600"
desired_capacity = "${var.ecs_desired_size}"
min_size = "${var.ecs_min_size}"
max_size = "${var.ecs_max_size}"
enabled_metrics = [
"GroupMinSize",
"GroupMaxSize",
"GroupDesiredCapacity",
"GroupInServiceInstances",
"GroupPendingInstances",
"GroupStandbyInstances",
"GroupTerminatingInstances",
"GroupTotalInstances"
]
}
data "aws_secretsmanager_secret" "ecs_host_key" {
name = "${lower(var.environment)}/ecs/ssh"
}
resource "aws_secretsmanager_secret_version" "ecs_host_key" {
secret_id = "${data.aws_secretsmanager_secret.ecs_host_key.id}"
secret_string = "${jsonencode(map("private_key", "${tls_private_key.key.private_key_pem}", "public_key", "${tls_private_key.key.public_key_openssh}"))}"
}
resource "tls_private_key" "key" {
algorithm = "RSA"
}
resource "aws_key_pair" "ecs_host_key" {
key_name = "${var.environment}-${var.service}-EcsContainerHostKey"
public_key = "${tls_private_key.key.public_key_openssh}"
}
resource "aws_security_group_rule" "ingress_allow_all" {
type = "ingress"
from_port = 0
to_port = 65535
protocol = "all"
cidr_blocks = [ "0.0.0.0/0" ]
security_group_id = "${module.ecs.container_instance_security_group_id}"
}
resource "aws_security_group_rule" "egress_allow_all" {
type = "egress"
from_port = 0
to_port = 65535
protocol = "all"
cidr_blocks = [ "0.0.0.0/0" ]
security_group_id = "${module.ecs.container_instance_security_group_id}"
}
data "aws_route53_zone" "zone" {
name = "${var.domain_hosted_zone}"
private_zone = "${var.private_dns_zone}"
}
resource "aws_route53_record" "gerrit" {
zone_id = "${data.aws_route53_zone.zone.zone_id}"
name = "${var.dns_alias}"
type = "A"
alias {
name = "${aws_alb.jenkins.dns_name}"
zone_id = "${aws_alb.jenkins.zone_id}"
evaluate_target_health = true
}
}