added duckdns
parent
f7caadaf84
commit
d467b5edd9
|
|
@ -4,7 +4,7 @@ Launches EC2 instance, creates private key, and saves it on the machine.
|
|||
|
||||
Usage:
|
||||
```
|
||||
terraform apply -var="instance_type=t2.nano" -var="instance_name=k3s-box" -var="instance_ami=ami-0889a44b331db0194" -var="availability_zone=us-east-1a" -var="create_ebs_block_device=false" - var="enable_ingress_http=false" -auto-approve
|
||||
terraform apply -var="instance_type=t2.nano" -var="instance_name=k3s-box" -var="instance_ami=ami-0889a44b331db0194" -var="availability_zone=us-east-1a" -var="create_ebs_block_device=false" - var="enable_ingress_http=false" -var="duckdns_domain=<duckdns_domain>" -var="duckdns_token=<duckdns_token>" -auto-approve
|
||||
```
|
||||
|
||||
Defaults of vars are set to the ones provided in "Usage"
|
||||
21
ec2.tf
21
ec2.tf
|
|
@ -12,7 +12,26 @@ resource "aws_instance" "k3s_box" {
|
|||
count = var.create_ebs_block_device ? 1 : 0
|
||||
}
|
||||
|
||||
user_data = "${file("./script.sh")}"
|
||||
# user_data = "${file("./setup_scripts/script.sh")}"
|
||||
|
||||
provisioner "file" {
|
||||
source = "./setup_scripts/install_crontab.sh"
|
||||
destination = "/home/ec2-user"
|
||||
}
|
||||
|
||||
provisioner "file" {
|
||||
source = "./setup_scripts/duckdns.sh"
|
||||
destination = "/home/ec2-user"
|
||||
}
|
||||
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"chmod +x /home/ec2-user/install_crontab.sh",
|
||||
"/home/ec2-user/install_crontab.sh",
|
||||
"chmod +x /home/ec2-user/duckdns.sh",
|
||||
"/home/ec2-user/duckdns.sh ${var.duckdns_domain} ${var.duckdns_token}"
|
||||
]
|
||||
}
|
||||
|
||||
tags = {
|
||||
Name = var.instance_name
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
#! /bin/bash
|
||||
|
||||
mkdir duckdns
|
||||
cd duckdns
|
||||
touch duck.sh
|
||||
echo url="https://www.duckdns.org/update?domains=$1&token=$2&ip=" | curl -k -o ~/duckdns/duck.log -K -
|
||||
chmod 700 duck.sh
|
||||
sudo touch /var/spool/cron/root
|
||||
sudo echo "*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1" >> /var/spool/cron/root
|
||||
./duck.sh
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#! /bin/bash
|
||||
|
||||
sudo yum install cronie -y
|
||||
sudo systemctl enable crond.service
|
||||
sudo systemctl start crond.service
|
||||
sudo systemctl status crond.service > /home/ec2-user/crontab-status.txt
|
||||
10
variables.tf
10
variables.tf
|
|
@ -26,4 +26,14 @@ variable "create_ebs_block_device" {
|
|||
variable "enable_ingress_http" {
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "duckdns_domain" {
|
||||
type = string
|
||||
default = "None"
|
||||
}
|
||||
|
||||
variable "duckdns_token" {
|
||||
type = string
|
||||
default = "None"
|
||||
}
|
||||
Loading…
Reference in New Issue