-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
64 lines (55 loc) · 1.47 KB
/
main.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
locals {
vpc_id = "vpc-0548d408bf3549ca0"
subnet_id = "subnet-060a1ae52cf0a73d6"
ssh_user = "ubuntu"
key_name = "devops"
private_key_path = "~/Downloads/sudeep.pem"
}
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "nginx" {
name = "nginx_access"
vpc_id = local.vpc_id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "nginx" {
ami = "ami-0dba2cb6798deb6d8"
subnet_id = "subnet-060a1ae52cf0a73d6"
instance_type = "t2.micro"
associate_public_ip_address = true
security_groups = [aws_security_group.nginx.id]
key_name = local.key_name
provisioner "remote-exec" {
inline = ["echo 'Wait until SSH is ready'"]
connection {
type = "ssh"
user = local.ssh_user
private_key = file(local.private_key_path)
host = aws_instance.nginx.public_ip
}
}
provisioner "local-exec" {
command = "ansible-playbook -i ${aws_instance.nginx.public_ip}, --private-key ${local.private_key_path} nginx.yaml"
}
}
output "nginx_ip" {
value = aws_instance.nginx.public_ip
}