-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.tf
More file actions
42 lines (35 loc) · 928 Bytes
/
Copy pathinstance.tf
File metadata and controls
42 lines (35 loc) · 928 Bytes
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
#providing data sources for ami
data "aws_ami" "ubuntu" {
most_recent = true
owners = ["${var.ownername}"]
filter {
name = "name"
values = ["${var.image-name}"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
#automation of ec2-instance
resource "aws_instance" "aws-ec2" {
ami = data.aws_ami.ubuntu.id
instance_type = var.instance-type
key_name = aws_key_pair.key-pair-ec2.key_name #assinging key-pair to an instance
associate_public_ip_address = true
vpc_security_group_ids = ["${aws_security_group.security-group-ec2.id}"]
tags = {
Name = "aws-ec2-tf"
}
user_data = file("${path.module}/userData.sh")
}
output "elastic-ip" {
value = aws_eip.nodejs.public_ip
}
output "image-id" {
value = aws_instance.aws-ec2.ami
}