-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstance.tf
70 lines (52 loc) · 1.27 KB
/
instance.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
### AWS INSTANCE
resource "aws_instance" "dev_work" {
depends_on = [aws_internet_gateway.gw]
ami = var.ami_id == null ? data.aws_ami.ubuntu.id : var.ami_id
metadata_options {
http_tokens = "required"
}
network_interface {
network_interface_id = aws_network_interface.ni.id
device_index = 0
}
instance_type = var.instance_type
key_name = aws_key_pair.ssh_key.key_name
tags = {
Name = "${var.name}_instance"
Created = timestamp()
}
root_block_device {
encrypted = true
volume_size = 100
}
}
resource "aws_eip" "ec2" {
vpc = true
}
resource "aws_network_interface" "ni" {
subnet_id = aws_subnet.public.id
security_groups = [aws_security_group.ec2.id]
tags = {
Name = "${var.name}_network_interface"
}
}
resource "aws_eip_association" "eip_assoc" {
instance_id = aws_instance.dev_work.id
allocation_id = aws_eip.ec2.id
}
resource "aws_key_pair" "ssh_key" {
key_name = "dev_key"
public_key = var.ssh_public_key
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}