-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
40 lines (28 loc) · 797 Bytes
/
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
# Create EC2 instance
resource "aws_instance" "tjc_ec2" {
ami = "ami-022e1a32d3f742bd8"
instance_type = var.ec2size
key_name = var.keyName
vpc_security_group_ids = [aws_security_group.toms-sg.id]
tags = {Name = "Terraform EC2"}
# Copy in the bash script we want to execute.
provisioner "file" {
source = "~/setup-ec2.sh"
destination = "/tmp/setup-ec2.sh"
}
# Change permissions on bash script and execute from ec2-user.
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/setup-ec2.sh",
"sudo /tmp/setup-ec2.sh",
]
}
# Login to the ec2-user with the aws pem key.
connection {
type = "ssh"
user = "ec2-user"
password = ""
private_key = file(var.keyPath)
host = self.public_ip
}
}