-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasg.tf
79 lines (62 loc) · 1.78 KB
/
asg.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
locals {
user_data = var.user_data != "" ? var.user_data : <<-EOT
#!/bin/bash
echo "Hello Terraform!"
EOT
}
data "aws_ami" "amazon_linux" {
most_recent = true
filter {
name = "name"
values = [var.ami_filter.filter_name]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = [var.ami_filter.owner] # the current account
}
module "asg" {
source = "terraform-aws-modules/autoscaling/aws"
version = "v6.10.0"
# Autoscaling group
name = local.full_service_name
vpc_zone_identifier = var.vpc_zone_identifier # module.vpc.private_subnets
min_size = 1
max_size = 1
desired_capacity = 1
# Launch template
create_launch_template = true
launch_template_name = local.full_service_name
launch_template_description = "Launch template for SSM proxy hosts"
update_default_version = true
image_id = data.aws_ami.amazon_linux.id
instance_type = var.instance_type # "t3.micro"
user_data = base64encode(local.user_data)
# instance profile setup
create_iam_instance_profile = false # as we need to use our own precreated instance profile
iam_instance_profile_arn = module.iam_assumable_role_ssm.iam_instance_profile_arn
# Security setup
security_groups = [aws_security_group.this.id]
# Autoscaling Schedule
schedules = var.schedules
# tags
tag_specifications = [
{
resource_type = "instance"
tags = local.tags_app_module
},
{
resource_type = "volume"
tags = local.tags_app_module
},
# {
# resource_type = "spot-instances-request"
# tags = merge({ WhatAmI = "SpotInstanceRequest" })
# }
]
tags = merge(
{},
local.tags_app_module
)
}