Skip to content

Commit 8d8ffbb

Browse files
author
linuxpatch
committed
initial commit
0 parents  commit 8d8ffbb

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Terraform Module: Install and Manage linuxpatch.com Agent and Service
2+
3+
## Description
4+
5+
This Terraform module automates the process of downloading, executing, and cleaning up an installation script from [linuxpatch.com](https://linuxpatch.com). Additionally, it ensures that the `linuxpatch-agent` service is running and enabled at startup.
6+
7+
## Prerequisites
8+
9+
- Terraform installed on the control node.
10+
- SSH access to the target host.
11+
- API key for [linuxpatch.com](https://linuxpatch.com).
12+
- SSH private key for authentication.
13+
14+
## Variables
15+
16+
- `api_key`: The API key required for the script execution. You should replace the placeholder with your actual API key.
17+
- `target_host`: The target host where the script will be executed.
18+
19+
## Usage
20+
21+
1. **Clone the repository or create the module files**:
22+
23+
Save the module content into a directory named `linuxpatch`.
24+
25+
2. **Set up the variables**:
26+
27+
Open `variables.tf` and define the variables `api_key` and `target_host`.
28+
29+
3. **Run Terraform Init**:
30+
31+
Initialize the Terraform module.
32+
33+
```bash
34+
terraform init
35+
```

main.tf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
provider "null" {
2+
version = ">= 2.1.0"
3+
}
4+
5+
provider "local" {
6+
version = ">= 1.4.0"
7+
}
8+
9+
resource "local_file" "install_script" {
10+
content = <<EOF
11+
#!/bin/bash
12+
curl -L https://linuxpatch.com/install.sh -o /tmp/install.sh
13+
chmod +x /tmp/install.sh
14+
EOF
15+
filename = "/tmp/install_script.sh"
16+
}
17+
18+
resource "null_resource" "run_install_script" {
19+
depends_on = [local_file.install_script]
20+
21+
provisioner "remote-exec" {
22+
connection {
23+
type = "ssh"
24+
user = "root"
25+
host = var.target_host
26+
private_key = file("<path_to_your_private_key>")
27+
}
28+
29+
inline = [
30+
"bash /tmp/install_script.sh",
31+
"API_KEY=${var.api_key} /tmp/install.sh",
32+
]
33+
}
34+
35+
provisioner "remote-exec" {
36+
when = destroy
37+
connection {
38+
type = "ssh"
39+
user = "root"
40+
host = var.target_host
41+
private_key = file("<path_to_your_private_key>")
42+
}
43+
44+
inline = [
45+
"rm -f /tmp/install.sh /tmp/install_script.sh",
46+
]
47+
}
48+
}
49+
50+
resource "null_resource" "ensure_service" {
51+
depends_on = [null_resource.run_install_script]
52+
53+
provisioner "remote-exec" {
54+
connection {
55+
type = "ssh"
56+
user = "root"
57+
host = var.target_host
58+
private_key = file("<path_to_your_private_key>")
59+
}
60+
61+
inline = [
62+
"systemctl enable linuxpatch-agent",
63+
"systemctl start linuxpatch-agent",
64+
]
65+
}
66+
}

outputs.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
output "install_script" {
2+
value = local_file.install_script.filename
3+
}
4+
5+
output "run_install_script_status" {
6+
value = null_resource.run_install_script.id
7+
}
8+
9+
output "ensure_service_status" {
10+
value = null_resource.ensure_service.id
11+
}

variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "api_key" {
2+
description = "API key for linuxpatch.com"
3+
type = string
4+
}
5+
6+
variable "target_host" {
7+
description = "Target host where the script will be executed"
8+
type = string
9+
}

0 commit comments

Comments
 (0)