-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
57 lines (48 loc) · 1.28 KB
/
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
52
53
54
55
56
57
provider "aws" {
region = "us-west-2"
}
variable "ip_address" {
description = "External IP address"
}
variable "proxy_port" {
description = "Proxy port for incoming requests"
default = 8888
}
output "proxy_ip_address" {
value = aws_instance.tinyproxy-terraform.public_ip
description = "Public IP address of the proxy server"
}
output "proxy_port" {
value = var.proxy_port
description = "Port of the proxy server"
}
resource "aws_instance" "tinyproxy-terraform" {
ami = "ami-0d1cd67c26f5fca19"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.instance.id]
user_data = <<-EOF
#!/bin/bash
sudo apt update
sudo apt-get install tinyproxy -y
sudo echo "Allow ${var.ip_address}" >> /etc/tinyproxy/tinyproxy.conf
sudo systemctl restart tinyproxy
EOF
tags = {
Name = "tinyproxy"
}
}
resource "aws_security_group" "instance" {
name = "tinyproxy-terraform-instance"
ingress {
from_port = var.proxy_port
to_port = var.proxy_port
protocol = "tcp"
cidr_blocks = ["${var.ip_address}/32"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}