Skip to content

Commit 4c37329

Browse files
Create instances.tf
1 parent 119499c commit 4c37329

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
resource "aws_instance" "web1" {
2+
ami = "enter-ami-id"
3+
instance_type = "t2.micro"
4+
subnet_id = "enter-subnet-id"
5+
vpc_security_group_ids = [aws_security_group.allow_http_instances.id]
6+
key_name = "enter-key-name"
7+
provisioner "remote-exec" {
8+
inline = [
9+
"sudo yum install httpd -y",
10+
"sudo service httpd start",
11+
"sudo chkconfig httpd on"
12+
]
13+
14+
connection {
15+
type = "ssh"
16+
user = "ec2-user"
17+
host = aws_instance.web.public_ip
18+
private_key = file("${path.module}/key-name.pem")
19+
}
20+
21+
}
22+
}
23+
24+
resource "aws_instance" "web2" {
25+
ami = "enter-ami-id"
26+
instance_type = "t2.micro"
27+
subnet_id = "enter-your-subnet-id"
28+
vpc_security_group_ids = [aws_security_group.allow_http_instances.id]
29+
key_name = "enter-key-name"
30+
provisioner "remote-exec" {
31+
inline = [
32+
"sudo yum install https -y",
33+
"sudo service httpd start",
34+
"sudo chkconfig httpd on"
35+
]
36+
37+
connection {
38+
type = "ssh"
39+
user = "ec2-user"
40+
host = aws_instance.web2.public_ip
41+
private_key = file("${path.module}/kay-name.pem")
42+
}
43+
44+
}
45+
}

0 commit comments

Comments
 (0)