-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
94 lines (74 loc) · 2.14 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
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
provider "aws" {
region = "us-east-1"
default_tags {
tags = {
Name = "tf-ecs"
Provisioner = "Terraform"
Repository = "https://github.com/ericdahl/tf-ecs"
}
}
}
module "vpc" {
source = "github.com/ericdahl/tf-vpc"
}
resource "aws_ecs_capacity_provider" "default" {
name = var.name
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.default.arn
managed_scaling {
status = "ENABLED"
target_capacity = 100
}
managed_termination_protection = "DISABLED"
managed_draining = "ENABLED"
}
}
resource "aws_ecs_cluster" "default" {
name = var.name
}
resource "aws_ecs_cluster_capacity_providers" "default" {
cluster_name = aws_ecs_cluster.default.name
capacity_providers = [aws_ecs_capacity_provider.default.name]
default_capacity_provider_strategy {
weight = 100
capacity_provider = aws_ecs_capacity_provider.default.name
}
}
data "template_file" "cloud_init" {
template = file("${path.module}/templates/cloud-init.yml")
vars = {
cluster_name = var.name
}
}
resource "aws_security_group" "ecs_instance" {
vpc_id = module.vpc.vpc_id
name = "ecs"
tags = {
Name = "ecs-instance"
}
}
resource "aws_security_group_rule" "ecs_instance_egress" {
security_group_id = aws_security_group.ecs_instance.id
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "ecs_instance_ingress_vpc" {
security_group_id = aws_security_group.ecs_instance.id
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["10.0.0.0/8"] # TODO: remove rule and replace with specific
}
data "aws_ssm_parameter" "ecs_amazon_linux_2023" {
name = "/aws/service/ecs/optimized-ami/amazon-linux-2023/recommended/image_id"
}
data "aws_ssm_parameter" "ecs_bottlerocket" {
name = "/aws/service/bottlerocket/aws-ecs-1/x86_64/latest/image_id"
}
data "aws_iam_role" "autoscaling" {
name = "AWSServiceRoleForApplicationAutoScaling_ECSService"
}