· 9 years ago · Jan 21, 2017, 10:28 PM
1provider "aws" {
2 access_key = "${var.access_key}"
3 secret_key = "${var.secret_key}"
4 region = "${var.region}"
5}
6
7resource "aws_security_group" "node_server" {
8 name = "node_server"
9 description = "Inbound SSH and outbound HTTP"
10
11 ingress {
12 from_port = 22
13 to_port = 22
14 protocol = "tcp"
15 cidr_blocks = ["0.0.0.0/0"]
16 }
17
18 ingress {
19 from_port = 80
20 to_port = 80
21 protocol = "tcp"
22 cidr_blocks = ["0.0.0.0/0"]
23 }
24
25 egress {
26 from_port = 0
27 to_port = 10000
28 protocol = "tcp"
29 cidr_blocks = ["0.0.0.0/0"]
30 }
31}
32
33resource "aws_instance" "node_server" {
34 ami = "ami-13be557e"
35 instance_type = "t2.micro"
36 key_name = "Terraform"
37
38 security_groups = ["node_server"]
39
40 connection {
41 type = "ssh"
42 user = "ubuntu"
43 private_key = "${file("Terraform.pem")}"
44 }
45
46 provisioner "file" {
47 source = "app"
48 destination = "/home/ubuntu"
49 }
50
51 provisioner "remote-exec" {
52 script = "setup.sh"
53 }
54}
55
56output "address" {
57 value = "${aws_instance.node_server.public_dns}"
58}