11resource "aws_launch_template" "LT" {
2- name = " ${ var . cluster_name } -spot "
2+ name = var. cluster_name
33
44 dynamic instance_market_options {
55 for_each = var. spot ? [1 ] : []
@@ -15,7 +15,7 @@ resource "aws_launch_template" "LT" {
1515
1616 image_id = data. aws_ami . ami . id
1717 instance_type = var. instance_type
18- vpc_security_group_ids = [ data . aws_security_group . group . id ]
18+ vpc_security_group_ids = var . security_group_ids
1919
2020 iam_instance_profile {
2121 arn = aws_iam_instance_profile. ec2-instance-role . arn
@@ -24,41 +24,40 @@ resource "aws_launch_template" "LT" {
2424 key_name = var. ec2_key_name
2525 user_data = data. template_cloudinit_config . config . rendered
2626 depends_on = [aws_iam_instance_profile . ec2-instance-role ]
27- }
28-
29- resource "aws_autoscaling_group" "ASG" {
30- name = var. cluster_name
31- max_size = var. instances_desired
32- min_size = var. instances_desired
3327
34- desired_capacity = var. instances_desired
28+ tags = var. tags
29+ }
3530
36- force_delete = true
31+ resource "aws_autoscaling_group" "asg" {
32+ name = var. cluster_name
33+ max_size = var. instances_desired
34+ min_size = var. instances_desired
35+ desired_capacity = var. instances_desired
36+ force_delete = true
37+ vpc_zone_identifier = var. subnet_ids
38+ termination_policies = [" OldestInstance" ]
3739
3840 launch_template {
3941 id = aws_launch_template. LT . id
4042 version = " $Latest"
4143 }
4244
43- vpc_zone_identifier = coalescelist (var. subnet_ids , list (data. aws_subnet_ids . subnets . ids ))
44- termination_policies = [" OldestInstance" ]
45-
46- tag {
47- key = " Name"
48- value = " ${ var . cluster_name } -ecs"
49- propagate_at_launch = true
50- }
51-
52- tag {
53- key = " ecs-cluster"
54- value = var. cluster_name
55- propagate_at_launch = true
56- }
45+ tags = [
46+ {
47+ key = " Name"
48+ value = " ${ var . cluster_name } -ecs"
49+ propagate_at_launch = true
50+ },
51+ {
52+ key = " ecs-cluster"
53+ value = var.cluster_name
54+ propagate_at_launch = true
55+ },
56+ ]
5757
5858 depends_on = [aws_iam_instance_profile . ec2-instance-role ]
5959}
6060
61- resource "aws_ecs_cluster" "main " {
61+ resource "aws_ecs_cluster" "cluster " {
6262 name = var. cluster_name
6363}
64-
0 commit comments