Skip to content

Commit

Permalink
Upgraded to Terraform 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
gudlyf committed Nov 27, 2019
1 parent 4af7b1c commit 647b269
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 29 deletions.
39 changes: 21 additions & 18 deletions AWS/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ data "aws_ami" "amazon_linux" {
}

resource "aws_instance" "outline-server" {
ami = "${data.aws_ami.amazon_linux.id}"
ami = data.aws_ami.amazon_linux.id
instance_type = "t2.nano"

associate_public_ip_address = true
source_dest_check = false
security_groups = ["${aws_security_group.outline_sg.name}"]
iam_instance_profile = "${aws_iam_instance_profile.outline-server_instance_profile.name}"
security_groups = [aws_security_group.outline_sg.name]
iam_instance_profile = aws_iam_instance_profile.outline-server_instance_profile.name

key_name = "${aws_key_pair.ec2-key.key_name}"
key_name = aws_key_pair.ec2-key.key_name

user_data = "${data.template_file.deployment_shell_script.rendered}"
user_data = data.template_file.deployment_shell_script.rendered

provisioner "remote-exec" {
inline = [
Expand All @@ -35,10 +35,10 @@ resource "aws_instance" "outline-server" {
]

connection {
host = "${aws_instance.outline-server.public_ip}"
host = aws_instance.outline-server.public_ip
type = "ssh"
user = "ec2-user"
private_key = "${file("${var.private_key_file}")}"
private_key = file(var.private_key_file)
timeout = "1m"
}
}
Expand All @@ -54,10 +54,10 @@ resource "aws_instance" "outline-server" {
]

connection {
host = "${aws_instance.outline-server.public_ip}"
host = aws_instance.outline-server.public_ip
type = "ssh"
user = "ec2-user"
private_key = "${file("${var.private_key_file}")}"
private_key = file(var.private_key_file)
timeout = "1m"
}
}
Expand All @@ -68,10 +68,10 @@ resource "aws_instance" "outline-server" {

provisioner "local-exec" {
command = "rm -f ${var.client_config_path}/outline-install-details-${aws_instance.outline-server.public_ip}.txt"
when = "destroy"
when = destroy
}

tags {
tags = {
Name = "outline-server"
}
}
Expand All @@ -94,16 +94,17 @@ resource "aws_iam_role" "outline-server_ec2_role" {
]
}
EOF

}

resource "aws_iam_instance_profile" "outline-server_instance_profile" {
name = "outline-server_instance_profile"
role = "${aws_iam_role.outline-server_ec2_role.name}"
role = aws_iam_role.outline-server_ec2_role.name
}

resource "aws_iam_role_policy" "outline-server_ec2_role_policy" {
name = "outline-server_ec2_role_policy"
role = "${aws_iam_role.outline-server_ec2_role.id}"
role = aws_iam_role.outline-server_ec2_role.id

policy = <<EOF
{
Expand All @@ -121,18 +122,20 @@ resource "aws_iam_role_policy" "outline-server_ec2_role_policy" {
]
}
EOF

}

data "template_file" "deployment_shell_script" {
template = "${file("userdata.sh")}"
template = file("userdata.sh")

vars {
REGION = "${var.region}"
SECURITY_GROUP = "${aws_security_group.outline_sg.name}"
vars = {
REGION = var.region
SECURITY_GROUP = aws_security_group.outline_sg.name
}
}

resource "aws_key_pair" "ec2-key" {
key_name_prefix = "outline-key-"
public_key = "${file(var.public_key_file)}"
public_key = file(var.public_key_file)
}

8 changes: 6 additions & 2 deletions AWS/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
provider "aws" {
profile = "${var.profile}"
region = "${var.region}"
profile = var.profile
region = var.region
}

terraform {
required_version = ">= 0.12"
}
1 change: 1 addition & 0 deletions AWS/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
output "public_ip" {
value = "VPN IP Address: ${aws_instance.outline-server.public_ip}"
}

2 changes: 1 addition & 1 deletion AWS/sg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ resource "aws_security_group" "outline_sg" {
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

}

5 changes: 5 additions & 0 deletions AWS/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
region = "ca-central-1"
private_key_file = "../certs/outline"
public_key_file = "../certs/outline.pub"
client_config_path = "../client_configs"

6 changes: 3 additions & 3 deletions AWS/userdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ echo "Reset DNS settings ..."

echo "supersede domain-name-servers 1.1.1.1, 9.9.9.9;" >> /etc/dhcp/dhclient.conf

dhclient -r -v $INTERFACE && rm /var/lib/dhclient/dhclient.* ; dhclient -v $INTERFACE
dhclient -r -v ${INTERFACE} && rm /var/lib/dhclient/dhclient.* ; dhclient -v ${INTERFACE}

echo "Fully update ..."

Expand All @@ -34,8 +34,8 @@ grep "apiUrl" /var/log/outline-install.log >> /tmp/outline-install-details.txt
export VPN_PORT=$(docker logs shadowbox | grep "tcp server listening" | sed 's/.*0:\(.*\)/\1/' | tail -1)
export MGMT_PORT=$(grep apiUrl /tmp/outline-install-details.txt | sed -r 's/.*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:([0-9]*).*/\1/g')
echo "#####" >> /tmp/outline-install-details.txt
echo -e "\033[0;31mManagement TCP/UDP port number: $MGMT_PORT\033[0m" >> /tmp/outline-install-details.txt
echo -e "\033[0;33mAccess TCP/UDP port number: $VPN_PORT\033[0m" >> /tmp/outline-install-details.txt
echo -e "\033[0;31mManagement TCP/UDP port number: ${MGMT_PORT}\033[0m" >> /tmp/outline-install-details.txt
echo -e "\033[0;33mAccess TCP/UDP port number: ${VPN_PORT}\033[0m" >> /tmp/outline-install-details.txt
echo "#####" >> /tmp/outline-install-details.txt

echo "DONE!"
8 changes: 3 additions & 5 deletions AWS/variables.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
variable "profile" {}
variable "profile" {
}

variable "region" {
default = "ca-central-1"
}

variable "private_key_file" {
default = "../certs/outline"
}

variable "public_key_file" {
default = "../certs/outline.pub"
}

variable "client_config_path" {
default = "../client_configs"
}

0 comments on commit 647b269

Please sign in to comment.