-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.tf
64 lines (55 loc) · 1.36 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
variable "remote_ips" {
description = "Your IP address used to limit SSH access to the host. (ex[\"10.1.2.3/32\"])"
type = "list"
default = ["192.168.1.60/32"]
}
resource "aws_vpc" "my_vpc" {
cidr_block = "172.16.0.0/16"
tags {
Name = "pranay-example"
}
}
resource "aws_subnet" "my_subnet" {
vpc_id = "${aws_vpc.my_vpc.id}"
cidr_block = "172.16.0.0/16"
availability_zone = "us-west-2a"
tags {
Name = "pranay.example"
}
}
resource "aws_network_interface" "foo" {
subnet_id = "${aws_subnet.my_subnet.id}"
private_ips = ["172.16.0.100"]
tags {
Name = "primary_network_interface"
}
}
##Security group##
resource "aws_security_group" "SSH" {
name = "SSH"
description = "Allow SSH only"
vpc_id = "${aws_vpc.my_vpc.id}"
}
resource "aws_security_group_rule" "SSH" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.SSH.id}"
}
resource "aws_security_group_rule" "SSH-1" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${var.remote_ips}"]
security_group_id = "${aws_security_group.SSH.id}"
}
##instance info##
resource "aws_instance" "foo" {
ami = "ami-e251209a" # us-west-2
instance_type = "t2.micro"
key_name = "shopinpal"
vpc_security_group_ids = ["${aws_security_group.SSH.id}"]
}