-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathec2.tf
82 lines (66 loc) · 1.94 KB
/
ec2.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
data "aws_ami" "amazonlinux" {
most_recent = true
owners = ["amazon"]
filter {
name = "owner-alias"
values = ["amazon"]
}
filter {
name = "name"
values = ["amzn2-ami-hvm*-x86_64-gp2"]
}
}
resource "aws_autoscaling_group" "this" {
name_prefix = "${local.bastion_name}-"
launch_configuration = aws_launch_configuration.this.name
max_size = var.max_count
min_size = var.min_count
desired_capacity = var.desired_count
health_check_type = "EC2"
vpc_zone_identifier = var.asg_subnets
target_group_arns = [aws_lb_target_group.this.arn]
termination_policies = ["OldestLaunchConfiguration"]
force_delete = true
instance_refresh {
strategy = "Rolling"
triggers = ["tag"]
}
tag {
key = "Name"
value = aws_launch_configuration.this.name
propagate_at_launch = true
}
dynamic "tag" {
for_each = var.tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_launch_configuration" "this" {
name_prefix = "${local.bastion_name}-"
image_id = data.aws_ami.amazonlinux.id
instance_type = var.instance_type
associate_public_ip_address = var.associate_public_ip_address
enable_monitoring = true
iam_instance_profile = aws_iam_instance_profile.this.name
key_name = var.key_name
security_groups = [aws_security_group.this.id]
root_block_device {
encrypted = true
}
user_data = templatefile("${path.module}/user_data.sh.tmpl", {
aws_region = local.region
bucket_name = aws_s3_bucket.this.bucket
# sync_users_script = data.template_file.sync_users.rendered
sudoers = jsonencode(var.sudoers)
})
lifecycle {
create_before_destroy = true
}
}