-
Notifications
You must be signed in to change notification settings - Fork 1
/
instance.tf
38 lines (30 loc) · 889 Bytes
/
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
# Creating key-pair on AWS using SSH-public key
resource "aws_key_pair" "deployer" {
key_name = var.key-name
public_key = file("${path.module}/my-key.pub")
}
# Creating security group to restrict/allow inbound connectivity
resource "aws_security_group" "network-security-group" {
name = var.network-security-group-name
description = "Allow TLS inbound traffic"
ingress {
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "nsg-inbound"
}
}
# Creating Ubuntu EC2 instance
resource "aws_instance" "ubuntu-vm-instance" {
ami = var.ubuntu-ami
instance_type = var.ubuntu-instance-type
key_name = aws_key_pair.deployer.key_name
vpc_security_group_ids = [aws_security_group.network-security-group.id]
tags = {
Name = "ubuntu-vm"
}
}