-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.tf
103 lines (89 loc) · 2.45 KB
/
deploy.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
variable "region" {
default = "us-east-1"
}
provider "aws" {
# region = "${var.region}"
region = "us-east-1" # Virginia
# region = "us-east-2" # Ohio
# region = "us-west-1" # California
# region = "us-west-2" # Oregon
# region = "ap-south-1" # Mumbai
# region = "ap-northeast-1" # Tokyo
# region = "ap-northeast-2" # Seoul
# region = "ap-southeast-1" # Singapore
# region = "ap-southeast-2" # Sydney
# region = "eu-central-1" # Frankfurt
# region = "eu-west-1" # Ireland
# region = "eu-west-2" # London
# region = "eu-west-3" # Paris
# region = "eu-north-1" # Stockholm
# region = "ca-central-1" # Montreal
# region = "sa-east-1" # Sao Paulo
}
resource "aws_instance" "ssocks" {
count = 1 # number of copies to spin up - if you put 1000 here, your bill might surprise you...
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"
key_name = "ssocks_key"
security_groups = [
"${aws_security_group.ssh_https.name}"
]
provisioner "remote-exec" {
script = "scripts/provision.sh"
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("~/.ssh/ssocks_key.pem")}"
host = self.public_ip
}
}
# Return the public dns names into a local file for later use.
provisioner "local-exec" {
command = "echo ${self.public_dns} >> public_dns.txt"
}
}
resource "aws_security_group" "ssh_https" {
# count = 1
name = "ssh_https"
description = "Allow all inbound traffic"
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "ssh_https"
}
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
}
owners = ["099720109477"] # Canonical
}
resource "null_resource" "after_cleanup" {
provisioner "local-exec" {
when = destroy
command = "rm -f public_dns.txt"
}
}
resource "null_resource" "before_cleanup" {
provisioner "local-exec" {
command = "rm -f public_dns.txt"
}
}