-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-ec2.tf
69 lines (54 loc) · 1.23 KB
/
my-ec2.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
variable "instancecount" {
type = number
}
variable "apptype" {
}
variable "instancetype" {
type = map
default = {
"http" = "t2.micro"
"apache" = "t2.micro"
"java" = "t2.micro"
"erp" = "t3.small"
}
}
data "aws_ami" "http" {
most_recent = true
owners = ["self"]
filter {
name = "name"
values = ["http-image 2021-09-03T11-52-39.404Z"]
}
}
data "aws_ami" "apache" {
most_recent = true
owners = ["self"]
filter {
name = "name"
values = ["http-image 2021-09-03T11-52-39.404Z"]
}
}
resource "aws_instance" "http" {
ami = data.aws_ami.http.id
instance_type = var.instancetype[var.apptype]
count = var.apptype == "http" ? var.instancecount : 0
tags = {
Name = "HTTp-Instance"
}
#count = var.instancecount
}
resource "aws_instance" "apache" {
ami = data.aws_ami.http.id
instance_type = var.instancetype[var.apptype]
count = var.apptype == "apache" ? var.instancecount : 0
tags = {
Name = "Apache-Instance"
}
#count = var.instancecount
}
output "public_http_ip" {
value = var.apptype == "http" ? aws_instance.http.*.public_ip : null
}
output "public_apache_ip" {
value = var.apptype == "apache" ? aws_instance.apache.*.public_ip : null
}