-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterraform_ansible.tf
53 lines (42 loc) · 1.13 KB
/
terraform_ansible.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
provider "aws" {
region = "us-east-2"
access_key = "Your access key"
secret_key = "Your Sec key"
}
resource "aws_security_group" "allow_ssh" {
name = "allow_ssh"
description = "Allow SSH inbound traffic"
ingress {
description = "SSH into VPC"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
description = "Outbound Allowed"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "myec2" {
ami = "ami-00dfe2c7ce89a450b"
instance_type = "t2.micro"
key_name = "MyPAIR"
associate_public_ip_address = true
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
provisioner "remote-exec" {
inline = ["echo 'hello world'" ]
connection {
type = "ssh"
user = "ec2-user"
private_key = file("./MyPAIR.pem")
host = self.public_ip
}
}
provisioner "local-exec" {
command = "ansible-playbook -i ${aws_instance.myec2.public_ip}, --private-key ./MyPAIR.pem play.yml"
}
}