-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
62 lines (54 loc) · 1.6 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
/**
* # ![AWS](aws-logo.png) ECS Capacity Provider
*
* [![CI](https://github.com/figurate/terraform-aws-ecs-capacity-provider/actions/workflows/main.yml/badge.svg)](https://github.com/figurate/terraform-aws-ecs-capacity-provider/actions/workflows/main.yml)
*
*
* Purpose: Blueprints for AWS ECS Capacity Providers.
*/
data "aws_vpc" "tenant" {
default = var.vpc_default
tags = var.vpc_tags
}
data "aws_subnets" "tenant" {
filter {
name = "vpc-id"
values = [data.aws_vpc.tenant.id]
}
}
resource "aws_ecs_capacity_provider" "capacity_provider" {
name = var.name
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.capacity_provider.arn
managed_scaling {
status = "ENABLED"
target_capacity = 100
maximum_scaling_step_size = 1
}
}
}
resource "aws_autoscaling_group" "capacity_provider" {
name_prefix = "${var.name}-"
vpc_zone_identifier = data.aws_subnets.tenant.ids
max_size = var.asg_max_size
min_size = 0
desired_capacity = 0
capacity_rebalance = true
mixed_instances_policy {
instances_distribution {
on_demand_base_capacity = var.on_demand_base_capacity
on_demand_percentage_above_base_capacity = var.on_demand_percentage_above_base_capacity
}
launch_template {
launch_template_specification {
launch_template_id = var.launch_template
version = "$Latest"
}
}
}
tag {
key = "Name"
value = var.name
propagate_at_launch = true
}
}