-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.tf
63 lines (47 loc) · 1.83 KB
/
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
##########################################################################################
# Creating 1 EC2 Instances Private:
##########################################################################################
resource "aws_instance" "instance" {
depends_on = [aws_instance.instance_bastion,aws_nat_gateway.ngw]
count = length(aws_subnet.private_subnet.*.id)
ami = data.aws_ami.debian.id
instance_type = var.instance_type
subnet_id = element(aws_subnet.private_subnet.*.id, count.index)
security_groups = [aws_security_group.sghttp.id, ]
key_name = "InfraTILab"
tags = {
"Name" = "Instance-${count.index}"
"Environment" = "Test"
"CreatedBy" = "Terraform"
}
timeouts {
create = "10m"
}
user_data = <<-EOF
#!/bin/bash
echo "*** Installing apache2"
sudo apt update -y
sudo apt install apache2 -y
sudo echo "<h1> Welcome to my terraform InfraTI IP: $(ip route get 1.2.3.4 | awk '{print $7}') </h1>" | sudo tee "/var/www/html/index.html"
echo "*** Completed Installing apache2"
EOF
}
##########################################################################################
# Creating 1 EC2 Instances Public - Bastion Host:
##########################################################################################
resource "aws_instance" "instance_bastion" {
ami = data.aws_ami.debian.id
count = var.bastion_instances_count
instance_type = var.instance_type
subnet_id = aws_subnet.public_subnet.*.id[0]
security_groups = [aws_security_group.sgbastion.id]
key_name = "InfraTILab"
tags = {
"Name" = "Instance-Bastion"
"Environment" = "Test"
"CreatedBy" = "Terraform"
}
timeouts {
create = "10m"
}
}