-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.tf
More file actions
71 lines (58 loc) · 1.63 KB
/
instance.tf
File metadata and controls
71 lines (58 loc) · 1.63 KB
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
resource "aws_network_interface" "internal_IIP" {
subnet_id = "${aws_subnet.Public_Subnet1.id}"
private_ips = ["192.168.0.25"]
tags {
Name = "primary_network_interface"
}
depends_on = ["aws_security_group.allow_all_in"]
security_groups = ["${aws_security_group.allow_all_in.id}"]
}
//resource "aws_eip" "elastip_ip" {
// vpc = true
//}
//resource "aws_eip_association" "eip_assoc" {
// instance_id = "${aws_instance.first_intance.id}"
// allocation_id = "${aws_eip.elastip_ip.id}"
//}
resource "aws_instance" "first_intance" {
ami = "${var.ami["instance_ami"]}" //debian linux defined in variables
instance_type = "${var.ami["instance_type"]}"
network_interface {
network_interface_id = "${aws_network_interface.internal_IIP.id}"
device_index = 0
}
//security_groups =
//vpc_security_group_ids = ["${aws_security_group.allow_all_in.name}"]
key_name = "my_key"
tags {
Name = "Terraform_machine"
}
provisioner "remote-exec" {
inline = [
"sudo apt-get update && sudo apt-get install nginx -y",
]
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("~/.ssh/my_key.pem")}"
}
}
}
resource "aws_security_group" "allow_all_in" {
name = "SG allow_all_in"
description = "Additional VPC SG with full access to/from an instance"
vpc_id = "${aws_vpc.Main_VPC.id}"
# TCP access
ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}