-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2Instance.tf
34 lines (29 loc) · 992 Bytes
/
ec2Instance.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
resource "aws_instance" "server" {
ami = "ami-09e62f426f25ce0d8"
subnet_id = "subnet-cc288cfb"
instance_type = "t2.micro"
associate_public_ip_address = true
security_groups = [aws_security_group.server.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.server.public_ip
}
}
provisioner "local-exec" {
command = "ansible-playbook -i ${aws_instance.server.public_ip}, --private-key ${local.private_key_path} nmap.yml"
}
}
output "server_ip" {
value = aws_instance.server.public_ip
connection {
type = "ssh"
user = local.ssh_user
private_key = file(local.private_key_path)
host = aws_instance.server.public_ip
}
}