-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
51 lines (39 loc) · 919 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
41
42
43
44
45
46
47
48
49
50
51
## VARIABLES ##
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "private_key_path" {}
variable "key_name" {
default = "Testing"
}
## PROVIDERS ##
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "us-east-1"
}
## RESOURCES ##
resource "aws_instance" "nginx" {
ami = "ami-0ac019f4fcb7cb7e6"
instance_type = "t2.micro"
key_name = "${var.key_name}"
tags {
Name = "nginx"
}
connection {
user = "ubuntu"
private_key = "${file(var.private_key_path)}"
}
provisioner "local-exec" {
command = "echo ${aws_instance.nginx.public_ip} > ip_address.txt"
}
provisioner "remote-exec" {
inline = [
"sudo apt-get install nginx -y",
"sudo systemctl start nginx"
]
}
}
## OUTPUT ##
output "aws_instance_public_dns" {
value = "${aws_instance.nginx.public_dns}"
}