minimum files for terraform as a module

This commit is contained in:
Patrick CAO HUU THIEN 2022-11-30 18:14:01 +01:00
parent 83e831163d
commit acc427c902
2 changed files with 50 additions and 0 deletions

39
main.tf Normal file
View File

@ -0,0 +1,39 @@
# you must prefixe path with "${path.module}/"
resource "null_resource" "fail2ban" {
# triggers = {
# source = filesha256("${path.module}/script")
# }
connection {
type = "ssh"
user = "root"
host = var.connection_ip
private_key = var.connection_private_key
}
# provisioner "file" {
# source = "${path.module}/script"
# destination = "/tmp"
# }
provisioner "remote-exec" {
inline = [
"echo '#-----------------------'",
"echo '# module alpine_fail2ban'",
"echo '#-----------------------'",
"echo '# install fail2ban'",
"apk add fail2ban",
#
"echo '# enable service fail2ban'",
"rc-update add fail2ban",
"rc-service fail2ban start",
#
"echo '# install helpers'",
"ln -s /etc/fail2ban /root/fail2ban",
"ln -s 'fail2ban-client status' /etc/fail2ban/0_status",
"ln -s 'fail2ban-client set sshd unbanip x.x.x.x' /etc/fail2ban/1_unban",
"ln -s 'fail2ban-client reload sshd' /etc/fail2ban/2_reload",
"echo '# module DONE'",
]
}
}

11
variables.tf Normal file
View File

@ -0,0 +1,11 @@
variable "connection_ip" {
type = string
description = "ipv4"
}
variable "connection_private_key" {
type = string
description = "private key for terraform connection"
sensitive = true
}