-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
94 lines (79 loc) · 2.15 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
# /**
# We use an ecrypted Ubuntu image because we care :)
# **/
# resource "aws_ami_copy" "ubuntu-xenial-encrypted-ami" {
# name = "ubuntu-xenial-encrypted-ami"
# description = "An encrypted root ami based off ${data.aws_ami.ubuntu-xenial.id}"
# source_ami_id = data.aws_ami.ubuntu-xenial.id
# source_ami_region = "us-west-2"
# encrypted = "true"
# tags = {
# Name = "ubuntu-xenial-encrypted-ami"
# }
# }
# data "aws_ami" "encrypted-ami" {
# most_recent = true
# filter {
# name = "name"
# values = ["ubuntu-xenial-encrypted-ami"]
# }
# owners = ["self"]
# }
data "aws_ami" "ubuntu-xenial" {
most_recent = true
owners = ["099720109477"]
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
}
}
/**
Now for the actual instances - we use an auto-scaling group to ensure we always have something
**/
module "asg" {
source = "terraform-aws-modules/autoscaling/aws"
version = "~> 3.0"
name = "devbox-${var.name}"
# Launch configuration
lc_name = "devbox-${var.name}-lc"
image_id = data.aws_ami.ubuntu-xenial.id
instance_type = "t3.xlarge"
security_groups = [var.security_group]
associate_public_ip_address = true
recreate_asg_when_lc_changes = true
key_name = var.ssh_key_name
# ebs_block_device = [
# {
# device_name = "/dev/xvdz"
# volume_type = "gp2"
# volume_size = "50"
# delete_on_termination = true
# },
# ]
root_block_device = [
{
volume_size = "50"
volume_type = "gp2"
},
]
# Auto scaling group
asg_name = "asg-${var.name}"
vpc_zone_identifier = var.subnet_ids
health_check_type = "EC2"
min_size = 0
max_size = 1
desired_capacity = 1
wait_for_capacity_timeout = 0
tags = [
{
key = "Terraform"
value = "true"
propagate_at_launch = true
},
{
key = "Environment"
value = "damons-vpc"
propagate_at_launch = true
},
]
}